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

%config
    xinetd_enable="$openpkg_rc_def"
    xinetd_proclimit_auth="64"
    xinetd_proclimit_prog="64"
    xinetd_log_prolog="true"
    xinetd_log_epilog="true"
    xinetd_log_numfiles="10"
    xinetd_log_minsize="1M"
    xinetd_log_complevel="9"

%common
    xinetd_logfile="@l_prefix@/var/xinetd/xinetd.log"
    xinetd_pidfile="@l_prefix@/var/xinetd/xinetd.pid"
    xinetd_signal () {
        [ -f $xinetd_pidfile ] && kill -$1 `cat $xinetd_pidfile`
    }

%status -u @l_susr@ -o
    xinetd_usable="unknown"
    xinetd_active="no"
    rcService xinetd enable yes && \
        xinetd_signal 0 && xinetd_active="yes"
    echo "xinetd_enable=\"$xinetd_enable\""
    echo "xinetd_usable=\"$xinetd_usable\""
    echo "xinetd_active=\"$xinetd_active\""

%start -p 100 -u @l_susr@
    rcService xinetd enable yes || exit 0
    rcService xinetd active yes && exit 0
    @l_prefix@/sbin/xinetd \
        -filelog $xinetd_logfile \
        -pidfile $xinetd_pidfile \
        -logprocs $xinetd_proclimit_auth \
        -limit $xinetd_proclimit_prog \
        -stayalive

%stop -p 900 -u @l_susr@
    rcService xinetd enable yes || exit 0
    rcService xinetd active no  && exit 0
    xinetd_signal TERM
    sleep 2

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

%reload -p 100 -u @l_susr@
    rcService xinetd enable yes || exit 0
    rcService xinetd active no  && exit 0
    xinetd_signal HUP
    sleep 2

%daily -u @l_susr@
    rcService xinetd enable yes || exit 0
    shtool rotate -f \
        -n ${xinetd_log_numfiles} -s ${xinetd_log_minsize} -d \
        -z ${xinetd_log_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \
        -P "${xinetd_log_prolog}" \
        -E "${xinetd_log_epilog} && rc xinetd reload" \
        $xinetd_logfile

