#!@l_prefix@/lib/openpkg/bash @l_prefix@/etc/rc
##
##  rc.portfwd -- Run-Commands
##

%config
    portfwd_enable="$openpkg_rc_def"
    portfwd_flags=""
    portfwd_log_prolog="true"
    portfwd_log_epilog="true"
    portfwd_log_numfiles="10"
    portfwd_log_minsize="1M"
    portfwd_log_complevel="9"

%common
    portfwd_pidfile="@l_prefix@/var/portfwd/portfwd.pid"
    portfwd_signal () {
        [ -f $portfwd_pidfile ] && kill -$1 `cat $portfwd_pidfile`
    }

%status -u @l_susr@ -o
    portfwd_usable="unknown"
    portfwd_active="no"
    rcService portfwd enable yes && \
        portfwd_signal 0 && portfwd_active="yes"
    echo "portfwd_enable=\"$portfwd_enable\""
    echo "portfwd_usable=\"$portfwd_usable\""
    echo "portfwd_active=\"$portfwd_active\""

%start -u @l_susr@
    rcService portfwd enable yes || exit 0
    rcService portfwd active yes && exit 0
    @l_prefix@/sbin/portfwd -p $portfwd_pidfile $portfwd_flags

%stop -u @l_susr@
    rcService portfwd enable yes || exit 0
    rcService portfwd active no && exit 0
    portfwd_signal TERM

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

%daily -u @l_susr@
    rcService portfwd enable yes || exit 0
    shtool rotate -f \
        -n ${portfwd_log_numfiles} -s ${portfwd_log_minsize} -d \
        -z ${portfwd_log_complevel} -o @l_susr@ -g @l_mgrp@ -m 644 \
        -P "${portfwd_log_prolog}" \
        -E "${portfwd_log_epilog}; rc portfwd restart" \
        @l_prefix@/var/portfwd/portfwd.log

