#!@l_prefix@/lib/openpkg/bash @l_prefix@/etc/rc
##
##  rc.pb4sd -- Run-Commands for PB4SD
##

%config
    pb4sd_enable="yes"
    pb4sd_dbfile="@l_prefix@/var/pb4sd/pb4sd.db"
    pb4sd_logfile="@l_prefix@/var/pb4sd/pb4sd.log"
    pb4sd_pidfile="@l_prefix@/var/pb4sd/pb4sd.pid"
    pb4sd_grace="3600"
    pb4sd_exclude="127.0.0.0/8"
    pb4sd_log_prolog="true"
    pb4sd_log_epilog="true"
    pb4sd_log_numfiles="10"
    pb4sd_log_minsize="1M"
    pb4sd_log_complevel="9"

%start -p 200 -u root
    opServiceEnabled pb4sd || exit 0
    pb4sd_popserver="${pop_type:-qpopper}"
    pb4sd_infile="${pop_logfile:-@l_prefix@/var/qpopper/qpopper.log}"
    @l_prefix@/sbin/pb4sd \
        --daemon \
        --popserver="${pb4sd_popserver}" \
        --infile="${pb4sd_infile}" \
        --dbfile="${pb4sd_dbfile}" \
        --logfile="${pb4sd_logfile}" \
        --pidfile="${pb4sd_pidfile}" \
        --grace="${pb4sd_grace}" \
        --exclude="${pb4sd_exclude}"

%stop -p 200 -u root
    opServiceEnabled pb4sd || exit 0
    if [ -f ${pb4sd_pidfile} ]; then
        kill -TERM `cat ${pb4sd_pidfile}`
    fi

%daily -u root
    opServiceEnabled pb4sd || exit 0
    shtool rotate -f \
        -n${pb4sd_log_numfiles} -s${pb4sd_log_minsize} -d \
        -z${pb4sd_log_complevel} -o@l_musr@ -g@l_mgrp@ -m644 \
        -P "${pb4sd_log_prolog}" \
        -E "${pb4sd_log_epilog}" \
        ${pb4sd_logfile}

