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

%config
    arpalert_enable="$openpkg_rc_def"
    arpalert_flags=""
    arpalert_log_prolog="true"
    arpalert_log_epilog="true"
    arpalert_log_numfiles="10"
    arpalert_log_minsize="1M"
    arpalert_log_complevel="9"

%common
    arpalert_pidfile="@l_prefix@/var/arpalert/run/arpalert.pid"
    arpalert_logfile="@l_prefix@/var/arpalert/log/arpalert.log"
    arpalert_signal () {
        [ -f $arpalert_pidfile ] && kill -$1 `cat $arpalert_pidfile`
    }

%status -u @l_susr@ -o
    arpalert_usable="unknown"
    arpalert_active="no"
    rcService arpalert enable yes && \
        arpalert_signal 0 && arpalert_active="yes"
    echo "arpalert_enable=\"$arpalert_enable\""
    echo "arpalert_usable=\"$arpalert_usable\""
    echo "arpalert_active=\"$arpalert_active\""

%start -u @l_susr@
    rcService arpalert enable yes || exit 0
    rcService arpalert active yes && exit 0
    @l_prefix@/sbin/arpalert ${arpalert_flags}

%stop -u @l_susr@
    rcService arpalert enable yes || exit 0
    rcService arpalert active no  && exit 0
    arpalert_signal TERM
    sleep 2
    rm -f $arpalert_pidfile >/dev/null 2>&1 || true

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

%daily -u @l_susr@
    rcService arpalert enable yes || exit 0
    shtool rotate -f \
        -n ${arpalert_log_numfiles} -s ${arpalert_log_minsize} -d \
        -z ${arpalert_log_complevel} -m 664 -o @l_susr@ -g @l_mgrp@ \
        -P "${arpalert_log_prolog}" \
        -E "${arpalert_log_epilog}; rc arpalert restart" \
        $arpalert_logfile

