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

%config
    swhoisd_enable="$openpkg_rc_def"
    swhoisd_bind_addr="127.0.0.1"
    swhoisd_bind_port="43"
    swhoisd_delay="1"
    swhoisd_log_prolog="true"
    swhoisd_log_epilog="true"
    swhoisd_log_numfiles="10"
    swhoisd_log_minsize="1M"
    swhoisd_log_complevel="9"

%common
    swhoisd_logfile="@l_prefix@/var/swhoisd/swhoisd.log"
    swhoisd_pidfile="@l_prefix@/var/swhoisd/swhoisd.pid"
    swhoisd_signal () {
        [ -f $swhoisd_pidfile ] && kill -$1 `cat $swhoisd_pidfile`
    }

%status -u @l_susr@ -o
    swhoisd_usable="no"
    swhoisd_active="no"
    rcService swhoisd enable yes && \
        swhoisd_signal 0 && swhoisd_active="yes"
    echo "swhoisd_enable=\"$swhoisd_enable\""
    echo "swhoisd_usable=\"$swhoisd_usable\""
    echo "swhoisd_active=\"$swhoisd_active\""

%start -p 100 -u @l_susr@
    rcService swhoisd enable yes || exit 0
    rcService swhoisd active yes && exit 0
    @l_prefix@/sbin/swhoisd \
        -s -l -u @l_rusr@ -g @l_rusr@ \
        -H "${swhoisd_bind_addr}" -P "${swhoisd_bind_port}" \
        -d "${swhoisd_delay}"

%stop -p 900 -u @l_susr@
    rcService swhoisd enable yes || exit 0
    rcService swhoisd active no  && exit 0
    swhoisd_signal TERM
    sleep 2
    rm -f $swhoisd_pidfile >/dev/null 2>&1 || true

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

%daily -u @l_susr@
    rcService swhoisd enable yes || exit 0
    shtool rotate -f \
        -n ${swhoisd_log_numfiles} -s ${swhoisd_log_minsize} -d \
        -z ${swhoisd_log_complevel} -m 644 -o @l_rusr@ -g @l_rgrp@ \
        -P "${swhoisd_log_prolog}" \
        -E "${swhoisd_log_epilog}; rc swhoisd reload" \
        ${swhoisd_logfile}

