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

%config
    axkit_enable="$openpkg_rc_def"
    axkit_log_files="@l_prefix@/var/axkit/log/access.log"
    axkit_log_steps="10"
    axkit_log_minsize="10M"
    axkit_log_complevel="9"
    axkit_log_prolog="true"
    axkit_log_epilog="true"
    axkit_err_files="@l_prefix@/var/axkit/log/error.log"
    axkit_err_steps="10"
    axkit_err_minsize="1M"
    axkit_err_complevel="9"
    axkit_err_prolog="true"
    axkit_err_epilog="true"

%common
    axkit_pidfile="@l_prefix@/var/axkit/run/apache.pid"
    axkit_signal () {
        [ -f $axkit_pidfile ] && kill -$1 `cat $axkit_pidfile`
    }

%status -u @l_susr@ -o
    axkit_usable="unknown"
    axkit_active="no"
    rcService axkit enable yes && \
    @l_prefix@/sbin/apache -t \
        -f @l_prefix@/etc/axkit/axkit-apache.conf 2>/dev/null && \
        axkit_usable="yes"
    axkit_signal 0 && axkit_active="yes" && \
        axkit_active="yes"
    echo "axkit_enable=\"$axkit_enable\""
    echo "axkit_usable=\"$axkit_usable\""
    echo "axkit_active=\"$axkit_active\""

%start -u @l_susr@
    rcService axkit enable yes || exit 0
    rcService axkit active yes && exit 0
    @l_prefix@/sbin/apache \
        -f @l_prefix@/etc/axkit/axkit-apache.conf

%stop -u @l_susr@
    rcService axkit enable yes || exit 0
    rcService axkit active no  && exit 0
    axkit_signal TERM
    sleep 2

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

%daily -u @l_rusr@
    rcService axkit enable yes || exit 0
    if [ ".$axkit_log_files" != . ]; then
        shtool rotate -f \
            -n ${axkit_log_steps} -s ${axkit_log_minsize} -d \
            -z ${axkit_log_complevel} -o @l_musr@ -g @l_mgrp@ -m 644 \
            -P "$axkit_log_prolog" \
            -E "${axkit_apachectl} restaaxkit; $axkit_log_epilog" \
            $axkit_log_files
    fi
    if [ ".$axkit_err_files" != . ]; then
        shtool rotate -f \
            -n ${axkit_err_steps} -s ${axkit_err_minsize} -d \
            -z ${axkit_err_complevel} -o @l_musr@ -g @l_mgrp@ -m 644 \
            -P "$axkit_err_prolog" \
            -E "${axkit_apachectl} restaaxkit; $axkit_err_epilog" \
            $axkit_err_files
    fi

