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

%config
    rbldnsd_enable="$openpkg_rc_def"
    rbldnsd_bind="127.0.0.1/53"
    rbldnsd_flags=""
    rbldnsd_log_prolog="true"
    rbldnsd_log_epilog="true"
    rbldnsd_log_numfiles="10"
    rbldnsd_log_minsize="1M"
    rbldnsd_log_complevel="9"

%common
    rbldnsd_workdir="@l_prefix@/etc/rbldnsd"
    rbldnsd_statfile="@l_prefix@/var/rbldnsd/rbldnsd.stat"
    rbldnsd_logfile="@l_prefix@/var/rbldnsd/rbldnsd.log"
    rbldnsd_pidfile="@l_prefix@/var/rbldnsd/rbldnsd.pid"
    rbldnsd_signal () {
        [ -f $rbldnsd_pidfile ] && kill -$1 `cat $rbldnsd_pidfile`
    }

%status -u @l_rusr@ -o
    rbldnsd_usable="unknown"
    rbldnsd_active="no"
    rcService rbldnsd enable yes && \
        rbldnsd_signal 0 && rbldnsd_active="yes"
    echo "rbldnsd_enable=\"$rbldnsd_enable\""
    echo "rbldnsd_usable=\"$rbldnsd_usable\""
    echo "rbldnsd_active=\"$rbldnsd_active\""

%start -u @l_susr@
    rcService rbldnsd enable yes || exit 0
    rcService rbldnsd active yes && exit 0
    eval @l_prefix@/sbin/rbldnsd \
        -q \
        -u @l_rusr@:@l_rgrp@ \
        -b $rbldnsd_bind \
        -w $rbldnsd_workdir \
        -p $rbldnsd_pidfile \
        -l $rbldnsd_logfile \
        -s $rbldnsd_statfile \
        $rbldnsd_flags \
        `sed -ne '/^ *#.*$/d' -e '/^ *$/d' -e 'p' \
             <$rbldnsd_workdir/rbldnsd.zones`

%stop -u @l_susr@
    rcService rbldnsd enable yes || exit 0
    rcService rbldnsd active no && exit 0
    rbldnsd_signal TERM
    rm -f $rbldnsd_pidfile 2>/dev/null || true

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

%reload -u @l_susr@
    rcService rbldnsd enable yes || exit 0
    rcService rbldnsd active no && exit 0
    rbldnsd_signal HUP

%daily -u @l_susr@
    rcService rbldnsd enable yes || exit 0
    shtool rotate -f \
        -n ${rbldnsd_log_numfiles} -s ${rbldnsd_log_minsize} -d \
        -z ${rbldnsd_log_complevel} -o @l_rusr@ -g @l_rgrp@ -m 644 \
        -P "${rbldnsd_log_prolog}" \
        -E "${rbldnsd_log_epilog}; rc rbldnsd restart" \
        $rbldnsd_logfile

