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

%config
    milter_backscatter_enable="$openpkg_rc_def"
    milter_backscatter_prolog="true"
    milter_backscatter_epilog="true"
    milter_backscatter_numfiles="10"
    milter_backscatter_minsize="1M"
    milter_backscatter_complevel="9"

%common
    milter_backscatter_pidfile="@l_prefix@/var/milter-backscatter/milter-backscatter.pid"
    milter_backscatter_logfile="@l_prefix@/var/milter-backscatter/milter-backscatter.log"
    milter_backscatter_socket="@l_prefix@/var/milter/socket/milter-backscatter"
    milter_backscatter_signal () {
        [ -f $milter_backscatter_pidfile ] && kill -$1 `cat $milter_backscatter_pidfile`
    }

%status -u @l_susr@ -o
    milter_backscatter_usable="unknown"
    milter_backscatter_active="no"
    rcService milter-backscatter enable yes && \
        milter_backscatter_signal 0 && milter_backscatter_active="yes"
    echo "milter_backscatter_enable=\"$milter_backscatter_enable\""
    echo "milter_backscatter_usable=\"$milter_backscatter_usable\""
    echo "milter_backscatter_active=\"$milter_backscatter_active\""

%start -u @l_susr@
    rcService milter-backscatter enable yes || exit 0
    rcService milter-backscatter active yes && exit 0
    cmd="@l_prefix@/sbin/milter-backscatter"
    cmd="$cmd -u @l_rusr@"
    cmd="$cmd -g @l_rgrp@"
    cmd="$cmd -p local:$milter_backscatter_socket"
    cmd="$cmd -P $milter_backscatter_pidfile"
    ( umask 002
      rm -f $milter_backscatter_socket >/dev/null 2>&1 || true
      eval $cmd
    ) || exit $?

%stop -u @l_susr@
    rcService milter-backscatter enable yes || exit 0
    rcService milter-backscatter active no  && exit 0
    milter_backscatter_signal TERM
    sleep 2
    rm -f $milter_backscatter_pidfile >/dev/null 2>&1 || true
    rm -f $milter_backscatter_socket  >/dev/null 2>&1 || true

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

%daily -u @l_susr@
    rcService milter-backscatter enable yes || exit 0
    shtool rotate -f \
        -n $milter_backscatter_numfiles -s $milter_backscatter_minsize -d \
        -z $milter_backscatter_complevel -m 644 -o @l_rusr@ -g @l_rgrp@ \
        -P "$milter_backscatter_prolog" \
        -E "$milter_backscatter_epilog; rc milter-backscatter restart" \
        $milter_backscatter_logfile

