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

%config
    milter_header_enable="$openpkg_rc_def"
    milter_header_flags=""
    milter_header_user="@l_rusr@"
    milter_header_prolog="true"
    milter_header_epilog="true"
    milter_header_numfiles="10"
    milter_header_minsize="1M"
    milter_header_complevel="9"

%common
    milter_header_cfgfile="@l_prefix@/etc/milter-header/milter-header.cfg"
    milter_header_pidfile="@l_prefix@/var/milter-header/milter-header.pid"
    milter_header_logfile="@l_prefix@/var/milter-header/milter-header.log"
    milter_header_socket="@l_prefix@/var/milter/socket/milter-header"
    milter_header_signal () {
        [ -f $milter_header_pidfile ] && kill -$1 `cat $milter_header_pidfile`
    }

%status -u @l_rusr@ -o
    milter_header_usable="unknown"
    milter_header_active="no"
    rcService milter-header enable yes && \
        milter_header_signal 0 && milter_header_active="yes"
    echo "milter_header_enable=\"$milter_header_enable\""
    echo "milter_header_usable=\"$milter_header_usable\""
    echo "milter_header_active=\"$milter_header_active\""

%start -u @l_rusr@
    rcService milter-header enable yes || exit 0
    rcService milter-header active yes && exit 0
    ( umask 002
      nohup @l_prefix@/bin/milter-header $milter_header_cfgfile </dev/null >/dev/null 2>&1 &
      echo $! >$milter_header_pidfile
    ) >/dev/null 2>&1

%stop -u @l_rusr@
    rcService milter-header enable yes || exit 0
    rcService milter-header active no  && exit 0
    milter_header_signal TERM
    sleep 2
    rm -f $milter_header_pidfile >/dev/null 2>&1 || true
    rm -f $milter_header_socket  >/dev/null 2>&1 || true

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

%daily -u @l_rusr@
    rcService milter-header enable yes || exit 0
    shtool rotate -f \
        -n $milter_header_numfiles -s $milter_header_minsize -d \
        -z $milter_header_complevel -m 644 -o @l_rusr@ -g @l_rgrp@ \
        -P "$milter_header_prolog" \
        -E "$milter_header_epilog; rc milter-header restart" \
        $milter_header_logfile

