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

%config
    smtpfeed_enable="no"
    smtpfeed_flags="-u -V"
    smtpfeed_bind_local="127.0.0.1:2525"
    smtpfeed_bind_remote="0.0.0.0"
    smtpfeed_hostname="localhost"
    smtpfeed_timeout_connect="1m"
    smtpfeed_timeout_greet="2m"
    smtpfeed_timeout_rset="2m"
    smtpfeed_maxrcpt="100"
    smtpfeed_maxsize="4194304"
    smtpfeed_log_prolog="true"
    smtpfeed_log_epilog="true"
    smtpfeed_log_numfiles="10"
    smtpfeed_log_minsize="1M"
    smtpfeed_log_complevel="9"

%common
    smtpfeed_pidfile="@l_prefix@/var/smtpfeed/smtpfeed.pid"
    smtpfeed_args="${smtpfeed_flags:--u -V} -E -l mail"
    smtpfeed_args="$smtpfeed_args -t connect=${smtpfeed_timeout_connect:-1m}"
    smtpfeed_args="$smtpfeed_args -t greet=${smtpfeed_timeout_greet:-2m}"
    smtpfeed_args="$smtpfeed_args -t rset=${smtpfeed_timeout_rset:-2m}"
    smtpfeed_args="$smtpfeed_args -o ${smtpfeed_bind_remote:-0.0.0.0}"
    smtpfeed_args="$smtpfeed_args -c ${smtpfeed_hostname:-localhost}"
    smtpfeed_args="$smtpfeed_args -r 1 -R ${smtpfeed_maxrcpt:-100}"
    smtpfeed_args="$smtpfeed_args -s ${smtpfeed_maxsize:-4194304}"
    smtpfeed_start () {
        ( @l_prefix@/sbin/smtpfeedd ${smtpfeed_bind_local:-127.0.0.1:2525} \
          @l_prefix@/sbin/smtpfeed ${smtpfeed_args} \
          </dev/null >/dev/null 2>&1 &
          echo "$!" >${smtpfeed_pidfile}
        ) </dev/null >/dev/null 2>&1
    }
    smtpfeed_stop () {
        if [ -f ${smtpfeed_pidfile} ]; then
            kill -TERM `cat ${smtpfeed_pidfile}`
            sleep 1
        fi
    }

%start -p 200 -u root
    opServiceEnabled smtpfeed || exit 0
    smtpfeed_start

%stop -p 200 -u root
    opServiceEnabled smtpfeed || exit 0
    smtpfeed_stop

%restart -u root
    opServiceEnabled smtpfeed || exit 0
    smtpfeed_stop
    sleep 1
    smtpfeed_start

%daily -u root
    opServiceEnabled smtpfeed || exit 0
    shtool rotate -f \
        -n${smtpfeed_log_numfiles} -s${smtpfeed_log_minsize} -d \
        -z${smtpfeed_log_complevel} -o@l_musr@ -g@l_mgrp@ -m644 \
        -P "$smtpfeed_log_prolog" \
        -E "$smtpfeed_log_epilog" \
        @l_prefix@/var/smtpfeed/smtpfeed.log

