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

%config
    cherokee_enable="$openpkg_rc_def"
    cherokee_log_files="@l_prefix@/var/cherokee/log/cherokee.access"
    cherokee_log_steps="10"
    cherokee_log_minsize="10M"
    cherokee_log_complevel="9"
    cherokee_log_prolog="true"
    cherokee_log_epilog="true"

%common
    cherokee_pidfile="@l_prefix@/var/cherokee/run/cherokee.pid"
    cherokee_signal () {
        [ -f $cherokee_pidfile ] && kill -$1 `cat $cherokee_pidfile`
    }

%status -u @l_susr@ -o
    cherokee_usable="no"
    cherokee_active="no"
    cherokee_usable="unknown"
    rcService cherokee enable yes && \
        cherokee_signal 0 && cherokee_active="yes"
    echo "cherokee_enable=\"$cherokee_enable\""
    echo "cherokee_usable=\"$cherokee_usable\""
    echo "cherokee_active=\"$cherokee_active\""

%start -u @l_susr@
    rcService cherokee enable yes || exit 0
    rcService cherokee active yes && exit 0
    @l_prefix@/sbin/cherokee --detach

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

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

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

%daily -u @l_susr@
    rcService cherokee enable yes || exit 0
    shtool rotate -f \
        -n ${cherokee_log_steps} -s ${cherokee_log_minsize} -d \
        -z ${cherokee_log_complevel} -o @l_nusr@ -g @l_ngrp@ -m 644 \
        -P "$cherokee_log_prolog" \
        -E "$cherokee_log_epilog" \
        ${cherokee_log_files}

