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

%config
    dcron_enable="$openpkg_rc_def"
    dcron_loglevel="8"
    dcron_log_prolog="true"
    dcron_log_epilog="true"
    dcron_log_numfiles="10"
    dcron_log_minsize="1M"
    dcron_log_complevel="9"

%common
    dcron_pidfile="@l_prefix@/var/dcron/dcron.pid"
    dcron_signal () {
        [ -f $dcron_pidfile ] && kill -$1 `cat $dcron_pidfile`
    }

%status -u @l_susr@ -o
    dcron_usable="unknown"
    dcron_active="no"
    rcService dcron enable yes && \
        dcron_signal 0 && dcron_active="yes"
    echo "dcron_enable=\"$dcron_enable\""
    echo "dcron_usable=\"$dcron_usable\""
    echo "dcron_active=\"$dcron_active\""

%start -u @l_susr@
    rcService dcron enable yes || exit 0
    rcService dcron active yes && exit 0
    (   PATH="@l_prefix@/bin:@l_prefix@/sbin:/bin:/sbin:/usr/bin:/usr/sbin"
        export PATH
        @l_prefix@/sbin/crond -l${dcron_loglevel} \
            >>@l_prefix@/var/dcron/dcron.log 2>&1
    ) || exit $?

%stop -u @l_susr@
    rcService dcron enable yes || exit 0
    rcService dcron active no && exit 0
    dcron_signal TERM
    rm -f @l_prefix@/var/dcron/dcron.pid 2>/dev/null || true

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

%daily -u @l_susr@
    rcService dcron enable yes || exit 0
    shtool rotate -f \
        -n ${dcron_log_numfiles} -s ${dcron_log_minsize} -d \
        -z ${dcron_log_complevel} -o @l_musr@ -g @l_mgrp@ -m 644 \
        -P "$dcron_log_prolog" \
        -E "$dcron_log_epilog && rc dcron restart" \
        @l_prefix@/var/dcron/dcron.log

