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

%config
    flowscan_enable="$openpkg_rc_def"
    flowscan_log_prolog="true"
    flowscan_log_epilog="true"
    flowscan_log_numfiles="10"
    flowscan_log_minsize="1M"
    flowscan_log_complevel="9"

%common
    flowscan_logfile="@l_prefix@/var/flowscan/flowscan.log"
    flowscan_pidfile="@l_prefix@/var/flowscan/flowscan.pid"
    flowscan_signal () {
        [ -f $flowscan_pidfile ] && kill -$1 `cat $flowscan_pidfile`
    }

%status -u @l_rusr@ -o
    flowscan_usable="unknown"
    flowscan_active="no"
    rcService flowscan enable yes && \
        flowscan_signal 0 && flowscan_active="yes"
    echo "flowscan_enable=\"$flowscan_enable\""
    echo "flowscan_usable=\"$flowscan_usable\""
    echo "flowscan_active=\"$flowscan_active\""

%start -u @l_rusr@
    rcService flowscan enable yes || exit 0
    rcService flowscan active yes && exit 0
    ( nohup @l_prefix@/bin/flowscan >>$flowscan_logfile 2>&1 </dev/null &
      echo $! >$flowscan_pidfile
    ) >/dev/null 2>&1

%stop -u @l_rusr@
    rcService flowscan enable yes || exit 0
    rcService flowscan active no && exit 0
    flowscan_signal TERM
    sleep 2
    rm -f $flowscan_pidfile 2>/dev/null || true

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

%daily -u @l_rusr@
    rcService flowscan enable yes || exit 0
    shtool rotate -f \
        -n ${flowscan_log_numfiles} -s ${flowscan_log_minsize} -d \
        -z ${flowscan_log_complevel} -o @l_rusr@ -g @l_rgrp@ -m 644 \
        -P "${flowscan_log_prolog}" \
        -E "${flowscan_log_epilog}; rc flowscan restart" \
        $flowscan_logfile

