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

%config
    portsentry_enable="$openpkg_rc_def"
    portsentry_log_prolog="true"
    portsentry_log_epilog="true"
    portsentry_log_numfiles="10"
    portsentry_log_minsize="1M"
    portsentry_log_complevel="9"

%common
    portsentry_tcp_pidfile="@l_prefix@/var/portsentry/tcp.pid"
    portsentry_udp_pidfile="@l_prefix@/var/portsentry/udp.pid"
    portsentry_signal () {
        [ -f $portsentry_tcp_pidfile ] \
        && kill -$1 `cat $portsentry_tcp_pidfile`
        local rc=$?

        [ -f $portsentry_udp_pidfile ] \
        && kill -$1 `cat $portsentry_udp_pidfile` \
        && [ $rc -eq 0 ]
    }

%status -u @l_susr@ -o
    portsentry_usable="unknown"
    portsentry_active="no"
    rcService portsentry enable yes && \
        portsentry_signal 0 && portsentry_active="yes"
    echo "portsentry_enable=\"$portsentry_enable\""
    echo "portsentry_usable=\"$portsentry_usable\""
    echo "portsentry_active=\"$portsentry_active\""

%start -u @l_susr@
    rcService portsentry enable yes || exit 0
    rcService portsentry active yes && exit 0
    @l_prefix@/sbin/portsentry -tcp $portsentry_tcp_pidfile
    @l_prefix@/sbin/portsentry -udp $portsentry_udp_pidfile

%stop -u @l_susr@
    rcService portsentry enable yes || exit 0
    rcService portsentry active no  && exit 0
    portsentry_signal TERM
    sleep 2

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

%daily -u @l_susr@
    rcService portsentry enable yes || exit 0
    shtool rotate -f \
        -n ${portsentry_log_numfiles} -s ${portsentry_log_minsize} -d \
        -z ${portsentry_log_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \
        -P "${portsentry_log_prolog}" \
        -E "${portsentry_log_epilog}; rc portsentry restart" \
        @l_prefix@/var/portsentry/portsentry.log

