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

%config
    milter_sid_enable="$openpkg_rc_def"
    milter_sid_flags="-D -h -r0 -t"
    milter_sid_user="@l_rusr@"
    milter_sid_prolog="true"
    milter_sid_epilog="true"
    milter_sid_numfiles="10"
    milter_sid_minsize="1M"
    milter_sid_complevel="9"

%common
    milter_sid_pidfile="@l_prefix@/var/milter-sid/milter-sid.pid"
    milter_sid_logfile="@l_prefix@/var/milter-sid/milter-sid.log"
    milter_sid_socket="@l_prefix@/var/milter/socket/milter-sid"
    milter_sid_signal () {
        [ -f $milter_sid_pidfile ] && kill -$1 `cat $milter_sid_pidfile`
    }

%status -u @l_susr@ -o
    milter_sid_usable="unknown"
    milter_sid_active="no"
    rcService milter-sid enable yes && \
        milter_sid_signal 0 && milter_sid_active="yes"
    echo "milter_sid_enable=\"$milter_sid_enable\""
    echo "milter_sid_usable=\"$milter_sid_usable\""
    echo "milter_sid_active=\"$milter_sid_active\""

%start -u @l_susr@
    rcService milter-sid enable yes || exit 0
    rcService milter-sid active yes && exit 0
    rm -f $milter_sid_socket >/dev/null 2>&2 || true
    ( umask 002
      @l_prefix@/sbin/sid-filter \
           -l -u $milter_sid_user \
           -p local:$milter_sid_socket \
           -P $milter_sid_pidfile \
           $milter_sid_flags
    ) || exit $?

%stop -u @l_susr@
    rcService milter-sid enable yes || exit 0
    rcService milter-sid active no  && exit 0
    milter_sid_signal TERM
    sleep 2
    rm -f $milter_sid_pidfile >/dev/null 2>&1 || true
    rm -f $milter_sid_socket  >/dev/null 2>&1 || true

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

%daily -u @l_susr@
    rcService milter-sid enable yes || exit 0
    shtool rotate -f \
        -n $milter_sid_numfiles -s $milter_sid_minsize -d \
        -z $milter_sid_complevel -m 644 -o @l_rusr@ -g @l_rgrp@ \
        -P "$milter_sid_prolog" \
        -E "$milter_sid_epilog; rc milter-sid restart" \
        $milter_sid_logfile

