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

%config
    nuster_enable="$openpkg_rc_def"
    nuster_log_prolog="true"
    nuster_log_epilog="true"
    nuster_log_numfiles="10"
    nuster_log_minsize="1M"
    nuster_log_complevel="9"

%common
    nuster_cfgfile="@l_prefix@/etc/nuster/nuster.cfg"
    nuster_logfile="@l_prefix@/var/nuster/nuster.log"
    nuster_pidfile="@l_prefix@/var/nuster/nuster.pid"
    nuster_signal () {
        [ -f $nuster_pidfile ] && kill -$1 `cat $nuster_pidfile`
    }

%status -u @l_susr@ -o
    nuster_usable="unknown"
    nuster_active="no"
    rcService nuster enable yes && \
        nuster_signal 0 && nuster_active="yes"
    echo "nuster_enable=\"$nuster_enable\""
    echo "nuster_usable=\"$nuster_usable\""
    echo "nuster_active=\"$nuster_active\""

%start -u @l_susr@
    rcService nuster enable yes || exit 0
    rcService nuster active yes && exit 0
    @l_prefix@/sbin/nuster -D -f $nuster_cfgfile -p $nuster_pidfile

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

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

%daily -u @l_susr@
    rcService nuster enable yes || exit 0
    shtool rotate -f \
        -n $nuster_log_numfiles -s $nuster_log_minsize -d \
        -z $nuster_log_complevel -m 664 -o @l_nusr@ -g @l_ngrp@ \
        -P "$nuster_log_prolog" \
        -E "$nuster_log_epilog; rc nuster restart" \
        $nuster_logfile

