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

%config
    milter_bogom_enable="$openpkg_rc_def"
    milter_bogom_flags=""
    milter_bogom_prolog="true"
    milter_bogom_epilog="true"
    milter_bogom_numfiles="10"
    milter_bogom_minsize="1M"
    milter_bogom_complevel="9"

%common
    milter_bogom_pidfile="@l_prefix@/var/milter-bogom/milter-bogom.pid"
    milter_bogom_logfile="@l_prefix@/var/milter-bogom/milter-bogom.log"
    milter_bogom_socket="@l_prefix@/var/milter/socket/milter-bogom"
    milter_bogom_signal () {
        [ -f $milter_bogom_pidfile ] && kill -$1 `cat $milter_bogom_pidfile`
    }

%status -u @l_susr@ -o
    milter_bogom_usable="unknown"
    milter_bogom_active="no"
    rcService milter-bogom enable yes && \
        milter_bogom_signal 0 && milter_bogom_active="yes"
    echo "milter_bogom_enable=\"$milter_bogom_enable\""
    echo "milter_bogom_usable=\"$milter_bogom_usable\""
    echo "milter_bogom_active=\"$milter_bogom_active\""

%start -u @l_susr@
    rcService milter-bogom enable yes || exit 0
    rcService milter-bogom active yes && exit 0
    ( umask 002
      rm -f $milter_bogom_socket >/dev/null 2>&1 || true
      @l_prefix@/sbin/bogom $milter_bogom_flags
    ) || exit $?

%stop -u @l_susr@
    rcService milter-bogom enable yes || exit 0
    rcService milter-bogom active no  && exit 0
    milter_bogom_signal TERM
    sleep 2
    rm -f $milter_bogom_pidfile >/dev/null 2>&1 || true
    rm -f $milter_bogom_socket  >/dev/null 2>&1 || true

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

%daily -u @l_susr@
    rcService milter-bogom enable yes || exit 0
    shtool rotate -f \
        -n $milter_bogom_numfiles -s $milter_bogom_minsize -d \
        -z $milter_bogom_complevel -m 644 -o @l_rusr@ -g @l_rgrp@ \
        -P "$milter_bogom_prolog" \
        -E "$milter_bogom_epilog; rc milter-bogom restart" \
        $milter_bogom_logfile

