#!@l_prefix@/bin/openpkg rc
##
##  rc.nextcloud -- Run-Commands
##

%config
    nextcloud_enable="$openpkg_rc_def"
    nextcloud_log_rotsteps="10"
    nextcloud_log_rotminsize="10M"
    nextcloud_log_rotcomplevel="9"
    nextcloud_log_rotprolog="true"
    nextcloud_log_rotepilog="true"

%common
    nextcloud_cfgfile="@l_prefix@/etc/nextcloud/nextcloud-apache.conf"
    nextcloud_pidfile="@l_prefix@/var/nextcloud/run/nextcloud-apache.pid"
    nextcloud_logfile="@l_prefix@/var/nextcloud/log/nextcloud-access.log"

%status -u @l_susr@ -o
    nextcloud_usable="no"
    nextcloud_active="no"
    @l_prefix@/sbin/apache -t -f $nextcloud_cfgfile 2>/dev/null && \
        nextcloud_usable="yes"
    [ -f $nextcloud_pidfile ] && \
        kill -0 `cat $nextcloud_pidfile` && \
        nextcloud_active="yes"
    echo "nextcloud_enable=\"$nextcloud_enable\""
    echo "nextcloud_usable=\"$nextcloud_usable\""
    echo "nextcloud_active=\"$nextcloud_active\""

%start -u @l_susr@
    rcService nextcloud enable yes || exit 0
    rcService nextcloud active yes && exit 0
    @l_prefix@/sbin/apache -f $nextcloud_cfgfile

%stop -u @l_susr@
    rcService nextcloud enable yes || exit 0
    rcService nextcloud active no  && exit 0
    [ -f $nextcloud_pidfile ] && \
        kill -TERM `cat $nextcloud_pidfile`
    sleep 2

%restart -u @l_susr@
    rcService nextcloud enable yes || exit 0
    rcService nextcloud active no  && exit 0
    rc nextcloud stop start

%reload -u @l_susr@
    rcService nextcloud enable yes || exit 0
    rcService nextcloud active no  && exit 0
    @l_prefix@/sbin/apache -f $nextcloud_cfgfile -k graceful

%daily -u @l_susr@
    rcService nextcloud enable yes || exit 0
    shtool rotate -f \
        -n $nextcloud_log_rotsteps -s $nextcloud_log_rotminsize -d \
        -z $nextcloud_log_rotcomplevel -o @l_rusr@ -g @l_rgrp@ -m 644 \
        -P "$nextcloud_log_rotprolog" \
        -E "$nextcloud_log_rotepilog; rc nextcloud reload" \
        $nextcloud_logfile

