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

%config
    boa_enable="$openpkg_rc_def"
    boa_flags=""
    boa_log_prolog="true"
    boa_log_epilog="true"
    boa_log_numfiles="10"
    boa_log_minsize="1M"
    boa_log_complevel="9"

%common
    boa_pidfile="@l_prefix@/var/boa/boa.pid"
    boa_signal () {
        [ -f $boa_pidfile ] && kill -$1 `cat $boa_pidfile`
    }

%status -u @l_susr@ -o
    boa_usable="unknown"
    boa_active="no"
    rcService boa enable yes && \
        boa_signal 0 && boa_active="yes"
    echo "boa_enable=\"$boa_enable\""
    echo "boa_usable=\"$boa_usable\""
    echo "boa_active=\"$boa_active\""

%start -u @l_susr@
    rcService boa enable yes || exit 0
    rcService boa active yes && exit 0
    @l_prefix@/sbin/boa ${boa_flags}

%stop -u @l_susr@
    rcService boa enable yes || exit 0
    rcService boa active no  && exit 0
    boa_signal TERM
    sleep 2
    rm -f $boa_pidfile >/dev/null 2>&1 || true

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

%reload -u @l_susr@
    rcService boa enable yes || exit 0
    rcService boa active no  && exit 0
    boa_signal HUP

%daily -u @l_susr@
    rcService boa enable yes || exit 0
    shtool rotate -f \
        -n ${boa_log_numfiles} -s ${boa_log_minsize} -d -c \
        -z ${boa_log_complevel} -m 644 -o @l_susr@ -g @l_sgrp@ \
        -P "${boa_log_prolog}" \
        -E "${boa_log_epilog}" \
        @l_prefix@/var/boa/boa.access.log
    shtool rotate -f \
        -n ${boa_log_numfiles} -s ${boa_log_minsize} -d -c \
        -z ${boa_log_complevel} -m 644 -o @l_susr@ -g @l_sgrp@ \
        -P "${boa_log_prolog}" \
        -E "${boa_log_epilog}" \
        @l_prefix@/var/boa/boa.error.log
    shtool rotate -f \
        -n ${boa_log_numfiles} -s ${boa_log_minsize} -d -c \
        -z ${boa_log_complevel} -m 644 -o @l_susr@ -g @l_sgrp@ \
        -P "${boa_log_prolog}" \
        -E "${boa_log_epilog}" \
        @l_prefix@/var/boa/boa.cgi.log

