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

%config
    owncloud_enable="$openpkg_rc_def"
    owncloud_log_rotsteps="10"
    owncloud_log_rotminsize="10M"
    owncloud_log_rotcomplevel="9"
    owncloud_log_rotprolog="true"
    owncloud_log_rotepilog="true"

%common
    owncloud_cfgfile="@l_prefix@/etc/owncloud/owncloud-apache.conf"
    owncloud_pidfile="@l_prefix@/var/owncloud/run/owncloud-apache.pid"
    owncloud_logfile="@l_prefix@/var/owncloud/log/owncloud-access.log"

%status -u @l_susr@ -o
    owncloud_usable="no"
    owncloud_active="no"
    @l_prefix@/sbin/apache -t -f $owncloud_cfgfile 2>/dev/null && \
        owncloud_usable="yes"
    [ -f $owncloud_pidfile ] && \
        kill -0 `cat $owncloud_pidfile` && \
        owncloud_active="yes"
    echo "owncloud_enable=\"$owncloud_enable\""
    echo "owncloud_usable=\"$owncloud_usable\""
    echo "owncloud_active=\"$owncloud_active\""

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

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

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

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

%daily -u @l_susr@
    rcService owncloud enable yes || exit 0
    shtool rotate -f \
        -n $owncloud_log_rotsteps -s $owncloud_log_rotminsize -d \
        -z $owncloud_log_rotcomplevel -o @l_rusr@ -g @l_rgrp@ -m 644 \
        -P "$owncloud_log_rotprolog" \
        -E "$owncloud_log_rotepilog; rc owncloud reload" \
        $owncloud_logfile

