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

%config
    pdnsd_enable="$openpkg_rc_def"
    pdnsd_flags="-s"
    pdnsd_log_prolog="true"
    pdnsd_log_epilog="true"
    pdnsd_log_numfiles="10"
    pdnsd_log_minsize="1M"
    pdnsd_log_complevel="9"

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

%status -u @l_susr@ -o
    pdnsd_usable="unknown"
    pdnsd_active="no"
    rcService pdnsd enable yes && \
        pdnsd_signal 0 && pdnsd_active="yes"
    echo "pdnsd_enable=\"$pdnsd_enable\""
    echo "pdnsd_usable=\"$pdnsd_usable\""
    echo "pdnsd_active=\"$pdnsd_active\""

%start -u @l_susr@
    rcService pdnsd enable yes || exit 0
    rcService pdnsd active yes && exit 0
    @l_prefix@/sbin/pdnsd --daemon -p $pdnsd_pidfile $pdnsd_flags

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

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

%daily -u @l_susr@
    rcService pdnsd enable yes || exit 0
    shtool rotate -f \
        -n ${pdnsd_log_numfiles} -s ${pdnsd_log_minsize} -d \
        -z ${pdnsd_log_complevel} -m 664 -o @l_rusr@ -g @l_rgrp@ \
        -P "${pdnsd_log_prolog}" \
        -E "${pdnsd_log_epilog}; rc pdnsd restart" \
        @l_prefix@/var/pdnsd/pdnsd.log

