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

%config
    confd_enable="$openpkg_rc_def"
    confd_log_prolog="true"
    confd_log_epilog="true"
    confd_log_numfiles="10"
    confd_log_minsize="1M"
    confd_log_complevel="9"

%common
    confd_pidfile="@l_prefix@/var/confd/run/confd.pid"
    confd_logfile="@l_prefix@/var/confd/log/confd.log"
    confd_signal () {
        [ -f $confd_pidfile ] && kill -$1 `cat $confd_pidfile`
    }

%status -u @l_susr@ -o
    confd_usable="unknown"
    confd_active="no"
    rcService confd enable yes && \
        confd_signal 0 && confd_active="yes"
    echo "confd_enable=\"$confd_enable\""
    echo "confd_usable=\"$confd_usable\""
    echo "confd_active=\"$confd_active\""

%start -u @l_susr@
    rcService confd enable yes || exit 0
    rcService confd active yes && exit 0
    (   nohup @l_prefix@/sbin/confd \
        </dev/null >>$confd_logfile 2>&1 &
        echo $! >$confd_pidfile
    ) >/dev/null 2>&1

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

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

%daily -u @l_susr@
    rcService confd enable yes || exit 0
    shtool rotate -f \
        -n ${confd_log_numfiles} -s ${confd_log_minsize} -d \
        -z ${confd_log_complevel} -m 664 -o @l_susr@ -g @l_sgrp@ \
        -P "${confd_log_prolog}" \
        -E "${confd_log_epilog}; rc confd restart" \
        $confd_logfile

