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

%config
    #   public (user-adjustable) options
    lmtp2nntp_enable="$openpkg_rc_def"
    lmtp2nntp_nice="20"
    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="nice -n $lmtp2nntp_nice"
    cmd_start="$cmd_start $lmtp2nntp_run_cmd"
    cmd_start="$cmd_start --daemonize"
    cmd_start="$cmd_start --include=$lmtp2nntp_run_cfg"

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

    #   determine UNIX-domain (PF_LOCAL) socket path being used, if any
    lmtp2nntp_pflocalpath=`sed <$lmtp2nntp_run_cfg -n -e 's;^bind [^/]*\(/.*\):.*$;\1;p'`

    #   standard daemon signal probe
    lmtp2nntp_pidfile="@l_prefix@/var/lmtp2nntp/lmtp2nntp.pid"
    lmtp2nntp_signal () {
        [ -f $lmtp2nntp_pidfile ] && kill -$1 `cat $lmtp2nntp_pidfile`
    }

%status -u @l_susr@ -o
    lmtp2nntp_usable="unknown"
    lmtp2nntp_active="no"
    rcService lmtp2nntp enable yes && \
        lmtp2nntp_signal 0 && lmtp2nntp_active="yes"
    echo "lmtp2nntp_enable=\"$lmtp2nntp_enable\""
    echo "lmtp2nntp_usable=\"$lmtp2nntp_usable\""
    echo "lmtp2nntp_active=\"$lmtp2nntp_active\""

%start -p 400 -u @l_susr@
    rcService lmtp2nntp enable yes || exit 0
    rcService lmtp2nntp active yes && exit 0
    eval $cmd_start
    sleep 2

%stop -p 600 -u @l_susr@
    rcService lmtp2nntp enable yes || exit 0
    rcService lmtp2nntp active no  && exit 0
    eval $cmd_stop
    sleep 2
    if [ ".$lmtp2nntp_pflocalpath" != . ]; then
        [ -S $lmtp2nntp_pflocalpath ] && rm -f $lmtp2nntp_pflocalpath
    fi

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

%daily -u @l_susr@
    rcService lmtp2nntp enable yes || exit 0
    shtool rotate -f \
        -n ${lmtp2nntp_log_numfiles} -s ${lmtp2nntp_log_minsize} -d \
        -z ${lmtp2nntp_log_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \
        -P "${lmtp2nntp_log_prolog}" \
        -E "${lmtp2nntp_log_epilog}; rc lmtp2nntp restart" \
        @l_prefix@/var/lmtp2nntp/lmtp2nntp.log

