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

%config
    milter_smc_enable="$openpkg_rc_def"
    milter_smc_flags=""
    milter_smc_prolog="true"
    milter_smc_epilog="true"
    milter_smc_numfiles="10"
    milter_smc_minsize="1M"
    milter_smc_complevel="9"

%common
    milter_smc_pidfile="@l_prefix@/var/milter-smc/milter-smc.pid"
    milter_smc_logfile="@l_prefix@/var/milter-smc/milter-smc.log"
    milter_smc_socket="@l_prefix@/var/milter/socket/milter-smc"
    milter_smc_signal () {
        [ -f $milter_smc_pidfile ] && kill -$1 `cat $milter_smc_pidfile`
    }

%status -u @l_rusr@ -o
    milter_smc_usable="unknown"
    milter_smc_active="no"
    rcService milter-smc enable yes && \
        milter_smc_signal 0 && milter_smc_active="yes"
    echo "milter_smc_enable=\"$milter_smc_enable\""
    echo "milter_smc_usable=\"$milter_smc_usable\""
    echo "milter_smc_active=\"$milter_smc_active\""

%start -u @l_rusr@
    rcService milter-smc enable yes || exit 0
    rcService milter-smc active yes && exit 0
    ( umask 002
      rm -f $milter_smc_socket >/dev/null 2>&1 || true
      @l_prefix@/sbin/milter-smc ${milter_smc_flags}
    ) || exit $?

%stop -u @l_rusr@
    rcService milter-smc enable yes || exit 0
    rcService milter-smc active no  && exit 0
    milter_smc_signal TERM
    sleep 2
    rm -f $milter_smc_pidfile >/dev/null 2>&1 || true
    rm -f $milter_smc_socket  >/dev/null 2>&1 || true

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

%daily -u @l_susr@
    rcService milter-smc enable yes || exit 0
    shtool rotate -f \
        -n $milter_smc_numfiles -s $milter_smc_minsize -d \
        -z $milter_smc_complevel -m 644 -o @l_rusr@ -g @l_rgrp@ \
        -P "$milter_smc_prolog" \
        -E "$milter_smc_epilog; rc milter-smc restart" \
        $milter_smc_logfile

