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

%config
    qpopper_enable="$openpkg_rc_def"
    qpopper_bind="127.0.0.1:110"
    qpopper_log_prolog="true"
    qpopper_log_epilog="true"
    qpopper_log_numfiles="10"
    qpopper_log_minsize="1M"
    qpopper_log_complevel="9"
    POP_type="qpopper"
    POP_logfile="@l_prefix@/var/qpopper/qpopper.log"

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

%status -u @l_susr@ -o
    qpopper_usable="unknown"
    qpopper_active="no"
    rcService qpopper enable yes && \
        qpopper_signal 0 && qpopper_active="yes"
    echo "qpopper_enable=\"$qpopper_enable\""
    echo "qpopper_usable=\"$qpopper_usable\""
    echo "qpopper_active=\"$qpopper_active\""

%start -u @l_susr@
    rcService qpopper enable yes || exit 0
    rcService qpopper active yes && exit 0
    @l_prefix@/sbin/qpopper ${qpopper_bind} -S -f @l_prefix@/etc/qpopper/qpopper.config

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

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

%daily -u @l_susr@
    rcService qpopper enable yes || exit 0
    shtool rotate -f \
        -n ${qpopper_log_numfiles} -s ${qpopper_log_minsize} -d \
        -z ${qpopper_log_complevel} -m 664 -o @l_susr@ -g @l_mgrp@ \
        -P "${qpopper_log_prolog}" \
        -E "${qpopper_log_epilog}; rc qpopper restart" \
        $POP_logfile

