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

%config
    unbound_enable="$openpkg_rc_def"
    unbound_log_prolog="true"
    unbound_log_epilog="true"
    unbound_log_numfiles="10"
    unbound_log_minsize="1M"
    unbound_log_complevel="9"

%common
    unbound_pidfile="@l_prefix@/var/unbound/run/unbound.pid"
    unbound_logfile="@l_prefix@/var/unbound/log/unbound.log"
    unbound_signal () {
        [ -f $unbound_pidfile ] && kill -$1 `cat $unbound_pidfile`
    }

%status -u @l_susr@ -o
    unbound_usable="unknown"
    unbound_active="no"
    rcService unbound enable yes && \
        unbound_signal 0 && unbound_active="yes"
    echo "unbound_enable=\"$unbound_enable\""
    echo "unbound_usable=\"$unbound_usable\""
    echo "unbound_active=\"$unbound_active\""

%start -u @l_susr@
    rcService unbound enable yes || exit 0
    rcService unbound active yes && exit 0
    @l_prefix@/sbin/unbound-control start

%stop -u @l_susr@
    rcService unbound enable yes || exit 0
    rcService unbound active no  && exit 0
    @l_prefix@/sbin/unbound-control stop
    sleep 2
    unbound_signal TERM
    rm -f $unbound_pidfile >/dev/null 2>&1 || true

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

%reload -u @l_susr@
    rcService unbound enable yes || exit 0
    rcService unbound active no  && exit 0
    @l_prefix@/sbin/unbound-control reload

%daily -u @l_susr@
    rcService unbound enable yes || exit 0
    shtool rotate -f \
        -n ${unbound_log_numfiles} -s ${unbound_log_minsize} -d \
        -z ${unbound_log_complevel} -m 664 -o @l_nusr@ -g @l_ngrp@ \
        -P "${unbound_log_prolog}" \
        -E "${unbound_log_epilog}; rc unbound reload" \
        $unbound_logfile

