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

%config
    powerdns_enable="$openpkg_rc_def"
    powerdns_pdns_file="@l_prefix@/var/powerdns/log/pdns.log"
    powerdns_pdns_prolog="true"
    powerdns_pdns_epilog="true"
    powerdns_pdns_numfiles="10"
    powerdns_pdns_minsize="1M"
    powerdns_pdns_complevel="9"
    powerdns_bindbe_file="@l_prefix@/var/powerdns/log/bindbe.log"
    powerdns_bindbe_prolog="true"
    powerdns_bindbe_epilog="true"
    powerdns_bindbe_numfiles="10"
    powerdns_bindbe_minsize="1M"
    powerdns_bindbe_complevel="9"
    powerdns_bind2be_file="@l_prefix@/var/powerdns/log/bind2be.log"
    powerdns_bind2be_prolog="true"
    powerdns_bind2be_epilog="true"
    powerdns_bind2be_numfiles="10"
    powerdns_bind2be_minsize="1M"
    powerdns_bind2be_complevel="9"
    powerdns_gsqlbe_file="@l_prefix@/var/powerdns/log/gsqlbe.log"
    powerdns_gsqlbe_prolog="true"
    powerdns_gsqlbe_epilog="true"
    powerdns_gsqlbe_numfiles="10"
    powerdns_gsqlbe_minsize="1M"
    powerdns_gsqlbe_complevel="9"

%common
    powerdns_pidfile="@l_prefix@/var/powerdns/pdns.pid"
    powerdns_sckfile="@l_prefix@/var/powerdns/pdns.controlsocket"
    powerdns_cfgfile="@l_prefix@/etc/powerdns/pdns.conf"
    powerdns_signal () {
        [ -f $powerdns_pidfile ] && kill -$1 `cat $powerdns_pidfile`
    }

%status -u @l_susr@ -o
    powerdns_usable="unknown"
    powerdns_active="no"
    rcService powerdns enable yes && \
        powerdns_signal 0 && powerdns_active="yes"
    echo "powerdns_enable=\"$powerdns_enable\""
    echo "powerdns_usable=\"$powerdns_usable\""
    echo "powerdns_active=\"$powerdns_active\""

%start -u @l_susr@
    rcService powerdns enable yes || exit 0
    rcService powerdns active yes && exit 0
    @l_prefix@/sbin/pdns_server --daemon=yes

%stop -u @l_susr@
    rcService powerdns enable yes || exit 0
    rcService powerdns active no && exit 0
    powerdns_signal TERM
    rm -f $powerdns_pidfile 2>/dev/null || true
    rm -f $powerdns_sckfile 2>/dev/null || true

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

%daily -u @l_susr@
    rcService powerdns enable yes || exit 0

    #   rotate logfiles
    shtool rotate -f \
        -n ${powerdns_pdns_numfiles} -s ${powerdns_pdns_minsize} -d \
        -z ${powerdns_pdns_complevel} -o @l_susr@ -g @l_mgrp@ -m 660 \
        -P "${powerdns_pdns_prolog}" \
        -E "${powerdns_pdns_epilog}" \
        ${powerdns_pdns_file}
    shtool rotate -f \
        -n ${powerdns_bindbe_numfiles} -s ${powerdns_bindbe_minsize} -d \
        -z ${powerdns_bindbe_complevel} -o @l_susr@ -g @l_mgrp@ -m 660 \
        -P "${powerdns_bindbe_prolog}" \
        -E "${powerdns_bindbe_epilog}" \
        ${powerdns_bindbe_file}
    shtool rotate -f \
        -n ${powerdns_bind2be_numfiles} -s ${powerdns_bind2be_minsize} -d \
        -z ${powerdns_bind2be_complevel} -o @l_susr@ -g @l_mgrp@ -m 660 \
        -P "${powerdns_bind2be_prolog}" \
        -E "${powerdns_bind2be_epilog}" \
        ${powerdns_bind2be_file}
    shtool rotate -f \
        -n ${powerdns_gsqlbe_numfiles} -s ${powerdns_gsqlbe_minsize} -d \
        -z ${powerdns_gsqlbe_complevel} -o @l_susr@ -g @l_mgrp@ -m 660 \
        -P "${powerdns_gsqlbe_prolog}" \
        -E "${powerdns_gsqlbe_epilog}" \
        ${powerdns_gsqlbe_file}

