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

%config
    whoson_enable="$openpkg_rc_def"
    whoson_log_prolog="true"
    whoson_log_epilog="true"
    whoson_log_numfiles="10"
    whoson_log_minsize="1M"
    whoson_log_complevel="9"

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

%status -u @l_susr@ -o
    whoson_usable="unknown"
    whoson_active="no"
    rcService whoson enable yes && \
        whoson_signal 0 && whoson_active="yes"
    echo "whoson_enable=\"$whoson_enable\""
    echo "whoson_usable=\"$whoson_usable\""
    echo "whoson_active=\"$whoson_active\""

%start -p 200 -u @l_susr@
    rcService whoson enable yes || exit 0
    rcService whoson active yes && exit 0
    @l_prefix@/sbin/whosond >$whoson_pidfile
    exit 0

%stop -p 910 -u @l_susr@
    rcService whoson enable yes || exit 0
    rcService whoson active no  && exit 0
    kill -TERM `cat $whoson_pidfile`
    rm -f $whoson_pidfile 2>/dev/null || true
    exit 0

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

%daily -u @l_susr@
    rcService whoson enable yes || exit 0
    shtool rotate -f \
        -n ${whoson_log_numfiles} -s ${whoson_log_minsize} -d \
        -z ${whoson_log_complevel} -o @l_rusr@ -g @l_rgrp@ -m 644 \
        -P "${whoson_log_prolog}" \
        -E "${whoson_log_epilog}" \
        @l_prefix@/var/whoson/log/whosond.log

