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

%config
    mta_name="postfix"
    mta_aliases_file="@l_prefix@/etc/postfix/aliases"
    mta_aliases_update="cd @l_prefix@/etc/postfix && @l_prefix@/sbin/postalias aliases"
    postfix_enable="yes"
    postfix_log_prolog="true"
    postfix_log_epilog="true"
    postfix_log_numfiles="10"
    postfix_log_minsize="1M"
    postfix_log_complevel="9"
    postfix_sum_flags=""

%start -p 200 -u @l_susr@
    opServiceEnabled postfix || exit 0
    @l_prefix@/sbin/postfix start

%stop -p 200 -u @l_susr@
    opServiceEnabled postfix || exit 0
    @l_prefix@/sbin/postfix stop

%restart -u @l_susr@
    opServiceEnabled postfix || exit 0
    @l_prefix@/sbin/postfix stop
    sleep 2
    @l_prefix@/sbin/postfix start

%reload -u @l_susr@
    opServiceEnabled postfix || exit 0
    @l_prefix@/sbin/postfix reload

%daily -u @l_susr@
    opServiceEnabled postfix || exit 0

    #   generate logfile summary
    shtool rotate -f \
        -n${postfix_log_numfiles} -s0 \
        -z${postfix_log_complevel} -o@l_musr@ -g@l_mgrp@ -m644 \
        @l_prefix@/var/postfix/log/postfix.sum
    logfiles="@l_prefix@/var/postfix/log/postfix.log"
    if [ -f "@l_prefix@/var/postfix/log/postfix.log.0" ]; then
        logfiles="$logfiles @l_prefix@/var/postfix/log/postfix.log.0"
    fi
    @l_prefix@/sbin/pflogsumm -d yesterday -h 10 -u 10 -i \
        --iso_date_time --problems_first --smtpd_stats --verbose_msg_detail \
        ${postfix_sum_flags} \
        ${logfiles} >@l_prefix@/var/postfix/log/postfix.sum 2>/dev/null

    #   rotate logfile
    shtool rotate -f \
        -n${postfix_log_numfiles} -s${postfix_log_minsize} -d \
        -z${postfix_log_complevel} -o@l_musr@ -g@l_mgrp@ -m644 \
        -P "$postfix_log_prolog" \
        -E "@l_prefix@/sbin/postfix reload; $postfix_log_epilog" \
        @l_prefix@/var/postfix/log/postfix.log

