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

%config
    nfdump_enable="$openpkg_rc_def"
    nfdump_flags="-b 127.0.0.1 -p 4432"
    nfdump_workdir="@l_prefix@/var/nfdump/db"
    nfdump_log_prolog="true"
    nfdump_log_epilog="true"
    nfdump_log_numfiles="10"
    nfdump_log_minsize="1M"
    nfdump_log_complevel="9"

%common
    nfdump_logfile="@l_prefix@/var/nfdump/nfdump.log"
    nfdump_pidfile="@l_prefix@/var/nfdump/nfdump.pid"
    nfdump_signal () {
        [ -f $nfdump_pidfile ] && kill -$1 `cat $nfdump_pidfile`
    }

%status -u @l_rusr@ -o
    nfdump_usable="unknown"
    nfdump_active="no"
    rcService nfdump enable yes && \
        nfdump_signal 0 && nfdump_active="yes"
    echo "nfdump_enable=\"$nfdump_enable\""
    echo "nfdump_usable=\"$nfdump_usable\""
    echo "nfdump_active=\"$nfdump_active\""

%start -u @l_rusr@
    rcService nfdump enable yes || exit 0
    rcService nfdump active yes && exit 0
    cmd="@l_prefix@/bin/nfcapd"
    cmd="$cmd $nfdump_flags"
    cmd="$cmd -D -P \"$nfdump_pidfile\""
    cmd="$cmd -l \"$nfdump_workdir\""
    eval $cmd

%stop -u @l_rusr@
    rcService nfdump enable yes || exit 0
    rcService nfdump active no  && exit 0
    nfdump_signal TERM
    sleep 2
    rm -f $nfdump_pidfile

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

%daily -u @l_rusr@
    rcService nfdump enable yes || exit 0
    shtool rotate -f \
        -n ${nfdump_log_numfiles} -s ${nfdump_log_minsize} -d \
        -z ${nfdump_log_complevel} -m 644 -o @l_rusr@ -g @l_rgrp@ \
        -P "${nfdump_log_prolog}" \
        -E "${nfdump_log_epilog}; rc nfdump restart" \
        $nfdump_logfile

