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

%config
    skipper_enable="$openpkg_rc_def"
    skipper_flags=""
    skipper_log_prolog="true"
    skipper_log_epilog="true"
    skipper_log_numfiles="10"
    skipper_log_minsize="1M"
    skipper_log_complevel="9"

%common
    skipper_cfgfile="@l_prefix@/etc/skipper/skipper.cfg"
    skipper_pidfile="@l_prefix@/var/skipper/run/skipper.pid"
    skipper_logfile="@l_prefix@/var/skipper/log/skipper.log"
    skipper_signal () {
        [ -f $skipper_pidfile ] && kill -$1 `cat $skipper_pidfile`
    }

%status -u @l_susr@ -o
    skipper_usable="unknown"
    skipper_active="no"
    rcService skipper enable yes && \
        skipper_signal 0 && skipper_active="yes"
    echo "skipper_enable=\"$skipper_enable\""
    echo "skipper_usable=\"$skipper_usable\""
    echo "skipper_active=\"$skipper_active\""

%start -u @l_susr@
    rcService skipper enable yes || exit 0
    rcService skipper active yes && exit 0
    (   nohup @l_prefix@/sbin/skipper \
           `sed -e "/^ *#/d" -e '/^ *$/d' -e "s;^;-;" <$skipper_cfgfile | \
           sed -e ":a" -e "N" -e '$!ba' -e 's/\n/ /g'` \
           $skipper_flags \
        </dev/null >>$skipper_logfile 2>&1 &
        echo $! >$skipper_pidfile
    ) >/dev/null 2>&1

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

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

%daily -u @l_susr@
    rcService skipper enable yes || exit 0
    shtool rotate -f \
        -n ${skipper_log_numfiles} -s ${skipper_log_minsize} -d \
        -z ${skipper_log_complevel} -m 664 -o @l_susr@ -g @l_sgrp@ \
        -P "${skipper_log_prolog}" \
        -E "${skipper_log_epilog}; rc skipper restart" \
        $skipper_logfile

