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

%config
    MTA_name="exim"
    MTA_aliases_file="@l_prefix@/etc/exim/aliases"
    MTA_aliases_update="true"
    exim_enable="$openpkg_rc_def"
    exim_spool="@l_prefix@/var/exim/spool"
    exim_flags="-bd -q30m"
    exim_tidydb_flags="-t 7d"
    exim_log_prolog="true"
    exim_log_epilog="true"
    exim_log_numfiles="10"
    exim_log_minsize="1M"
    exim_log_complevel="9"

%common
    exim_piddir="@l_prefix@/var/exim/run/"
    exim_signal () {
        local pid
        local rc=0
        for pid in `find $exim_piddir -name '*.pid'` ; do
            kill -$1 `cat $pid` || rc=1
        done
        [ ".$pid" != . -a $rc -eq 0 ]
    }

%status -u @l_susr@ -o
    exim_usable="no"
    exim_active="no"
    @l_prefix@/sbin/exim -bV >/dev/null 2>&1 && exim_usable="yes"
    rcService exim enable yes && \
        exim_signal 0 && exim_active="yes"
    echo "exim_enable=\"$exim_enable\""
    echo "exim_usable=\"$exim_usable\""
    echo "exim_active=\"$exim_active\""

%start -u @l_susr@
    rcService exim enable yes || exit 0
    rcService exim active yes && exit 0
    @l_prefix@/sbin/exim ${exim_flags}

%stop -u @l_susr@
    rcService exim enable yes || exit 0
    rcService exim active no  && exit 0
    exim_signal TERM

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

%reload -u @l_susr@
    rcService exim enable yes || exit 0
    rcService exim active no  && exit 0
    exim_signal HUP

%daily -u @l_susr@
    rcService exim enable yes || exit 0
    shtool rotate -f \
        -n ${exim_log_numfiles} -s ${exim_log_minsize} -d \
        -z ${exim_log_complevel} -o @l_rusr@ -g @l_rgrp@ -m 640 \
        -P "${exim_log_prolog}" \
        -E "${exim_log_epilog}" \
        @l_prefix@/var/exim/log/{main,panic,reject}.log

%weekly -u @l_rusr@
    rcService exim enable yes || exit 0
    if [ -d ${exim_spool}/db ]; then
        for db in `find ${exim_spool}/db/ -name \*.lockfile -o -type f -print |\
            sed -n -e 's;^.*/\([^/]*\)$;\1;p'`; do
            @l_prefix@/sbin/exim_tidydb ${exim_tidydb_flags} \
                ${exim_spool} ${db} >/dev/null
        done
    fi

