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

%config
    orangescrum_enable="$openpkg_rc_def"
    orangescrum_cron="yes"
    orangescrum_log_rotsteps="10"
    orangescrum_log_rotminsize="10M"
    orangescrum_log_rotcomplevel="9"
    orangescrum_log_rotprolog="true"
    orangescrum_log_rotepilog="true"

%common
    orangescrum_apache_cfgfile="@l_prefix@/etc/orangescrum/orangescrum-apache.conf"
    orangescrum_apache_pidfile="@l_prefix@/var/orangescrum/run/orangescrum-apache.pid"
    orangescrum_apache_logfile="@l_prefix@/var/orangescrum/log/orangescrum-access.log"

%status -u @l_susr@ -o
    orangescrum_usable="no"
    orangescrum_active="no"
    @l_prefix@/sbin/apache -t -f $orangescrum_apache_cfgfile 2>/dev/null && \
        orangescrum_usable="yes"
    [ -f $orangescrum_apache_pidfile ] && \
        kill -0 `cat $orangescrum_apache_pidfile` && \
        orangescrum_active="yes"
    echo "orangescrum_enable=\"$orangescrum_enable\""
    echo "orangescrum_usable=\"$orangescrum_usable\""
    echo "orangescrum_active=\"$orangescrum_active\""

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

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

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

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

%quarterly -u @l_rusr@
    rcService orangescrum enable yes || exit 0
    rcService orangescrum active no  && exit 0

%daily -u @l_susr@
    rcService orangescrum enable yes || exit 0
    if [ ".$orangescrum_cron" = .yes ]; then
        @l_prefix@/sbin/orangescrum-cron daily
    fi
    shtool rotate -f \
        -n $orangescrum_log_rotsteps -s $orangescrum_log_rotminsize -d \
        -z $orangescrum_log_rotcomplevel -o @l_susr@ -g @l_mgrp@ -m 644 \
        -P "$orangescrum_log_rotprolog" \
        -E "$orangescrum_log_rotepilog; rc orangescrum reload" \
        $orangescrum_apache_logfile

%weekly -u @l_susr@
    rcService orangescrum enable yes || exit 0
    if [ ".$orangescrum_cron" = .yes ]; then
        @l_prefix@/sbin/orangescrum-cron weekly
    fi

