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

%config
    ypanything_enable="$openpkg_rc_def"
    ypanything_log_prolog="true"
    ypanything_log_epilog="true"
    ypanything_log_numfiles="10"
    ypanything_log_minsize="1M"
    ypanything_log_complevel="9"

%common
    ypanything_cfgfile="@l_prefix@/etc/ypanything/ypanything.conf"
    ypanything_pidfile="@l_prefix@/var/ypanything/ypanything.pid"
    ypanything_logfile="@l_prefix@/var/ypanything/ypanything.log"
    ypanything_signal () {
        [ -f $ypanything_pidfile ] && kill -$1 `cat $ypanything_pidfile`
    }

%status -u @l_susr@ -o
    ypanything_usable="unknown"
    ypanything_active="no"
    rcService ypanything enable yes && \
        ypanything_signal 0 && ypanything_active="yes"
    echo "ypanything_enable=\"$ypanything_enable\""
    echo "ypanything_usable=\"$ypanything_usable\""
    echo "ypanything_active=\"$ypanything_active\""

%start -u @l_susr@
    rcService ypanything enable yes || exit 0
    rcService ypanything active yes && exit 0
    @l_prefix@/sbin/ypanything \
        -q -d -f $ypanything_cfgfile -p $ypanything_pidfile

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

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

%daily -u @l_susr@
    rcService ypanything enable yes || exit 0
    shtool rotate -f \
        -n ${ypanything_log_numfiles} -s ${ypanything_log_minsize} -d \
        -z ${ypanything_log_complevel} -m 664 -o @l_susr@ -g @l_mgrp@ \
        -P "${ypanything_log_prolog}" \
        -E "${ypanything_log_epilog}; rc ypanything restart" \
        $ypanything_logfile

