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

%config
    openslp_enable="$openpkg_rc_def"
    openslp_log_prolog="true"
    openslp_log_epilog="true"
    openslp_log_numfiles="10"
    openslp_log_minsize="1M"
    openslp_log_complevel="9"

%common
    openslp_pidfile="@l_prefix@/var/openslp/slpd.pid"
    openslp_logfile="@l_prefix@/var/openslp/slpd.log"
    openslp_signal () {
        [ -f $openslp_pidfile ] && kill -$1 `cat $openslp_pidfile`
    }

%status -u @l_susr@ -o
    openslp_usable="unknown"
    openslp_active="no"
    rcService openslp enable yes && \
        openslp_signal 0 && openslp_active="yes"
    echo "openslp_enable=\"$openslp_enable\""
    echo "openslp_usable=\"$openslp_usable\""
    echo "openslp_active=\"$openslp_active\""

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

%stop -u @l_susr@
    rcService openslp enable yes || exit 0
    rcService openslp active no  && exit 0
    openslp_signal TERM
    sleep 2
    rm -f $openslp_pidfile >/dev/null 2>&1 || true

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

%daily -u @l_susr@
    rcService openslp enable yes || exit 0
    shtool rotate -f \
        -n ${openslp_log_numfiles} -s ${openslp_log_minsize} -d \
        -z ${openslp_log_complevel} -m 664 -o @l_susr@ -g @l_mgrp@ \
        -P "${openslp_log_prolog}" \
        -E "${openslp_log_epilog}; rc openslp restart" \
        $openslp_logfile

