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

%config
    milter_greylist_enable="$openpkg_rc_def"
    milter_greylist_flags=""
    milter_greylist_user="@l_rusr@"
    milter_greylist_prolog="true"
    milter_greylist_epilog="true"
    milter_greylist_numfiles="10"
    milter_greylist_minsize="1M"
    milter_greylist_complevel="9"

%common
    milter_greylist_pidfile="@l_prefix@/var/milter-greylist/milter-greylist.pid"
    milter_greylist_logfile="@l_prefix@/var/milter-greylist/milter-greylist.log"
    milter_greylist_socket="@l_prefix@/var/milter/socket/milter-greylist"
    milter_greylist_signal () {
        [ -f $milter_greylist_pidfile ] && kill -$1 `cat $milter_greylist_pidfile`
    }

%status -u @l_susr@ -o
    milter_greylist_usable="unknown"
    milter_greylist_active="no"
    rcService milter-greylist enable yes && \
        milter_greylist_signal 0 && milter_greylist_active="yes"
    echo "milter_greylist_enable=\"$milter_greylist_enable\""
    echo "milter_greylist_usable=\"$milter_greylist_usable\""
    echo "milter_greylist_active=\"$milter_greylist_active\""

%start -u @l_susr@
    rcService milter-greylist enable yes || exit 0
    rcService milter-greylist active yes && exit 0
    rm -f $milter_greylist_socket >/dev/null 2>&2 || true
    (umask 002; @l_prefix@/sbin/milter-greylist $milter_greylist_flags)

%stop -u @l_susr@
    rcService milter-greylist enable yes || exit 0
    rcService milter-greylist active no  && exit 0
    milter_greylist_signal TERM
    sleep 2
    rm -f $milter_greylist_pidfile >/dev/null 2>&1 || true
    rm -f $milter_greylist_socket  >/dev/null 2>&1 || true

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

%daily -u @l_susr@
    rcService milter-greylist enable yes || exit 0
    shtool rotate -f \
        -n $milter_greylist_numfiles -s $milter_greylist_minsize -d \
        -z $milter_greylist_complevel -m 644 -o @l_rusr@ -g @l_rgrp@ \
        -P "$milter_greylist_prolog" \
        -E "$milter_greylist_epilog; rc milter-greylist restart" \
        $milter_greylist_logfile

