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

%config
    fprobe_enable="$openpkg_rc_def"
    fprobe_interface=""
    fprobe_filter=""
    fprobe_flags=""
    fprobe_collector="127.0.0.1:4432"
    fprobe_log_prolog="true"
    fprobe_log_epilog="true"
    fprobe_log_numfiles="10"
    fprobe_log_minsize="1M"
    fprobe_log_complevel="9"

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

%status -u @l_susr@ -o
    fprobe_usable="no"
    fprobe_active="no"
    [ ".$fprobe_interface" != . ] && fprobe_usable="yes"
    rcService fprobe enable yes && \
        fprobe_signal 0 && fprobe_active="yes"
    echo "fprobe_enable=\"$fprobe_enable\""
    echo "fprobe_usable=\"$fprobe_usable\""
    echo "fprobe_active=\"$fprobe_active\""

%start -u @l_susr@
    rcService fprobe enable yes || exit 0
    rcService fprobe active yes && exit 0
    cmd="@l_prefix@/sbin/fprobe"
    cmd="$cmd -i \"$fprobe_interface\""
    if [ ".$fprobe_filter" != . ]; then
        cmd="$cmd -f \"$fprobe_filter\""
    fi
    cmd="$cmd -l syslog"
    cmd="$cmd -u @l_nusr@"
    cmd="$cmd $fprobe_flags"
    cmd="$cmd $fprobe_collector"
    eval $cmd

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

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

%daily -u @l_susr@
    rcService fprobe enable yes || exit 0
    shtool rotate -f \
        -n ${fprobe_log_numfiles} -s ${fprobe_log_minsize} -d \
        -z ${fprobe_log_complevel} -m 644 -o @l_nusr@ -g @l_ngrp@ \
        -P "${fprobe_log_prolog}" \
        -E "${fprobe_log_epilog} && rc fprobe restart" \
        @l_prefix@/var/fprobe/fprobe.log

