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

%config
    rwhoisd_enable="$openpkg_rc_def"
    rwhoisd_log_prolog="true"
    rwhoisd_log_epilog="true"
    rwhoisd_log_numfiles="10"
    rwhoisd_log_minsize="1M"
    rwhoisd_log_complevel="9"

%common
    rwhoisd_cfgfile="@l_prefix@/etc/rwhoisd/rwhoisd.conf"
    rwhoisd_pidfile="@l_prefix@/var/rwhoids/rwhoisd.pid"
    rwhoisd_logfile="@l_prefix@/var/rwhoisd/rwhoisd.log"
    rwhoisd_signal () {
        [ -f $rwhoisd_pidfile ] && kill -$1 `cat $rwhoisd_pidfile`
    }

%status -u @l_rusr@ -o
    rwhoisd_usable="unknown"
    rwhoisd_active="no"
    rcService rwhoisd enable yes && \
        rwhoisd_signal 0 && rwhoisd_active="yes"
    echo "rwhoisd_enable=\"$rwhoisd_enable\""
    echo "rwhoisd_usable=\"$rwhoisd_usable\""
    echo "rwhoisd_active=\"$rwhoisd_active\""

%start -p 300 -u @l_rusr@
    rcService rwhoisd enable yes || exit 0
    rcService rwhoisd active yes && exit 0
    @l_prefix@/sbin/rwhoisd -c $rwhoisd_cfgfile -d

%stop -p 700 -u @l_rusr@
    rcService rwhoisd enable yes || exit 0
    rcService rwhoisd active yes || exit 0
    rwhoisd_signal TERM
    sleep 2
    rm -f $rwhoisd_pidfile >/dev/null 2>&1 || true

%restart -u @l_rusr@
    rcService rwhoisd enable yes || exit 0
    rc rwhoisd stop start

%reload -u @l_rusr@
    rcService rwhoisd enable yes || exit 0
    rcService rwhoisd active no  && exit 0
    rwhoisd_signal HUP

%daily -u @l_susr@
    rcService rwhoisd enable yes || exit 0
    @l_prefix@/sbin/rwhoisd -k rotate
    shtool rotate -f \
        -n ${rwhoisd_log_numfiles} -s ${rwhoisd_log_minsize} -d \
        -z ${rwhoisd_log_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \
        -P "${rwhoisd_log_prolog}" \
        -E "${rwhoisd_log_epilog}" \
        $rwhoisd_logfile

