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

%config
    rt_enable="$openpkg_rc_def"
    rt_log_files="@l_prefix@/var/rt/log/access.log"
    rt_log_steps="10"
    rt_log_minsize="10M"
    rt_log_complevel="9"
    rt_log_prolog="true"
    rt_log_epilog="true"
    rt_err_files="@l_prefix@/var/rt/log/error.log"
    rt_err_steps="10"
    rt_err_minsize="1M"
    rt_err_complevel="9"
    rt_err_prolog="true"
    rt_err_epilog="true"

%common
    rt_apachectl="@l_prefix@/libexec/rt/tools/rtapachectl"
    rt_sessiondir="@l_prefix@/var/rt/mason-session"
    rt_pidfile="@l_prefix@/var/rt/run/apache.pid"
    rt_signal () {
        [ -f $rt_pidfile ] && kill -$1 `cat $rt_pidfile`
    }

%status -u @l_susr@ -o
    rt_usable="unknown"
    rt_active="no"
    rcService rt enable yes && \
        rt_signal 0 && rt_active="yes"
    echo "rt_enable=\"$rt_enable\""
    echo "rt_usable=\"$rt_usable\""
    echo "rt_active=\"$rt_active\""

%start -u @l_rusr@
    rcService rt enable yes || exit 0
    rcService rt active yes && exit 0
    ${rt_apachectl} start

%stop -u @l_rusr@
    rcService rt enable yes || exit 0
    rcService rt active no  && exit 0
    ${rt_apachectl} stop
    sleep 2

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

%hourly -u @l_rusr@
    rcService rt enable yes || exit 0
    find $rt_sessiondir -type f -amin +600 -exec rm '{}' \;

%daily -u @l_rusr@
    rcService rt enable yes || exit 0
    if [ ".$rt_log_files" != . ]; then
        shtool rotate -f \
            -n ${rt_log_steps} -s ${rt_log_minsize} -d \
            -z ${rt_log_complevel} -o @l_musr@ -g @l_mgrp@ -m 644 \
            -P "$rt_log_prolog" \
            -E "${rt_apachectl} restart; $rt_log_epilog" \
            $rt_log_files
    fi
    if [ ".$rt_err_files" != . ]; then
        shtool rotate -f \
            -n ${rt_err_steps} -s ${rt_err_minsize} -d \
            -z ${rt_err_complevel} -o @l_musr@ -g @l_mgrp@ -m 644 \
            -P "$rt_err_prolog" \
            -E "${rt_apachectl} restart; $rt_err_epilog" \
            $rt_err_files
    fi

