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

%config
    milter_regex_enable="$openpkg_rc_def"
    milter_regex_flags=""
    milter_regex_user="@l_rusr@"
    milter_regex_prolog="true"
    milter_regex_epilog="true"
    milter_regex_numfiles="10"
    milter_regex_minsize="1M"
    milter_regex_complevel="9"

%common
    milter_regex_cfgfile="@l_prefix@/etc/milter-regex/milter-regex.conf"
    milter_regex_pidfile="@l_prefix@/var/milter-regex/milter-regex.pid"
    milter_regex_logfile="@l_prefix@/var/milter-regex/milter-regex.log"
    milter_regex_socket="@l_prefix@/var/milter/socket/milter-regex"
    milter_regex_signal () {
        [ -f $milter_regex_pidfile ] && kill -$1 `cat $milter_regex_pidfile`
    }

%status -u @l_susr@ -o
    milter_regex_usable="unknown"
    milter_regex_active="no"
    rcService milter-regex enable yes && \
        milter_regex_signal 0 && milter_regex_active="yes"
    echo "milter_regex_enable=\"$milter_regex_enable\""
    echo "milter_regex_usable=\"$milter_regex_usable\""
    echo "milter_regex_active=\"$milter_regex_active\""

%start -u @l_susr@
    rcService milter-regex enable yes || exit 0
    rcService milter-regex active yes && exit 0
    rm -f $milter_regex_socket >/dev/null 2>&2 || true
    ( umask 002
      nohup @l_prefix@/bin/milter-regex -d \
         -u $milter_regex_user \
         -c $milter_regex_cfgfile \
         -p $milter_regex_socket \
         $milter_regex_flags \
         </dev/null >/dev/null 2>&1 &
      echo $! >$milter_regex_pidfile
    ) >/dev/null 2>&1

%stop -u @l_susr@
    rcService milter-regex enable yes || exit 0
    rcService milter-regex active no  && exit 0
    milter_regex_signal TERM
    sleep 2
    rm -f $milter_regex_pidfile >/dev/null 2>&1 || true
    rm -f $milter_regex_socket  >/dev/null 2>&1 || true

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

%reload -u @l_susr@
    rcService milter-regex enable yes || exit 0
    milter_regex_signal HUP

%daily -u @l_susr@
    rcService milter-regex enable yes || exit 0
    shtool rotate -f \
        -n ${milter_regex_numfiles} -s ${milter_regex_minsize} -d \
        -z ${milter_regex_complevel} -m 644 -o @l_rusr@ -g @l_rgrp@ \
        -P "${milter_regex_prolog}" \
        -E "${milter_regex_epilog}; rc milter-regex restart" \
        ${milter_regex_logfile}

