#!@l_prefix@/lib/openpkg/bash @l_prefix@/etc/rc
##
##  rc.lmtp2nntp -- Run-Commands for LMTP2NNTP Daemon
##

%config
    #   public (user-adjustable) options
    lmtp2nntp_enable="yes"
    lmtp2nntp_log_level="info"
    lmtp2nntp_log_prolog="true"
    lmtp2nntp_log_epilog="true"
    lmtp2nntp_log_numfiles="10"
    lmtp2nntp_log_minsize="1M"
    lmtp2nntp_log_complevel="9"

%common
    #   private (not-adjustable) options
    lmtp2nntp_run_cmd="@l_prefix@/sbin/lmtp2nntp"
    lmtp2nntp_run_cfg="@l_prefix@/etc/lmtp2nntp/lmtp2nntp.conf"

    #   determine start command
    cmd_start="$lmtp2nntp_run_cmd"
    cmd_start="$cmd_start -D"
    cmd_start="$cmd_start --include=$lmtp2nntp_run_cfg"

    #   determine stop command
    cmd_stop="$lmtp2nntp_run_cmd"
    cmd_stop="$cmd_stop -K"
    cmd_stop="$cmd_stop --include=$lmtp2nntp_run_cfg"

%start -p 200 -u root
    opServiceEnabled lmtp2nntp || exit 0
    eval $cmd_start

%stop -p 200 -u root
    opServiceEnabled lmtp2nntp || exit 0
    eval $cmd_stop

%restart -u root
    opServiceEnabled lmtp2nntp || exit 0
    $cmd_stop
    sleep 1
    $cmd_start

%daily -u root
    opServiceEnabled lmtp2nntp || exit 0
    opTmpDirGen lmtp2nntp
    opTmpDirFile lmtp2nntp hint hintfile
    lmtp2nntp_log_epilog="echo 'epilog' >$hintfile; $lmtp2nntp_log_epilog"
    shtool rotate -f \
        -n ${lmtp2nntp_log_numfiles} -s ${lmtp2nntp_log_minsize} -d \
        -z ${lmtp2nntp_log_complevel} -o @l_musr@ -o @l_mgrp@ -m 644 \
        -P "$lmtp2nntp_log_prolog" -E "$lmtp2nntp_log_epilog" \
        @l_prefix@/var/lmtp2nntp/lmtp2nntp.log
    if [ ".`cat $hintfile`" = ".epilog" ]; then
        $cmd_stop
        sleep 1
        $cmd_start
    fi
    opTmpDirDel lmtp2nntp

