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

%config
    softflowd_enable="$openpkg_rc_def"
    softflowd_interface=""
    softflowd_collector="127.0.0.1:4432"
    softflowd_flags=""
    softflowd_log_prolog="true"
    softflowd_log_epilog="true"
    softflowd_log_numfiles="10"
    softflowd_log_minsize="1M"
    softflowd_log_complevel="9"

%status -u @l_susr@ -o
    softflowd_usable="no"
    softflowd_active="no"
    [ ".$softflowd_interface" != . ] && softflowd_usable="yes"
    @l_prefix@/sbin/softflowctl statistics >/dev/null 2>&1 && softflowd_active="yes"
    echo "softflowd_enable=\"$softflowd_enable\""
    echo "softflowd_usable=\"$softflowd_usable\""
    echo "softflowd_active=\"$softflowd_active\""

%start -u @l_susr@
    rcService softflowd enable yes || exit 0
    rcService softflowd active yes && exit 0
    @l_prefix@/sbin/softflowd \
        -i "$softflowd_interface" \
        -n "$softflowd_collector" \
        $softflowd_flags

%stop -u @l_susr@
    rcService softflowd enable yes || exit 0
    rcService softflowd active no  && exit 0
    @l_prefix@/sbin/softflowctl shutdown
    sleep 2

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

%daily -u @l_susr@
    rcService softflowd enable yes || exit 0
    shtool rotate -f \
        -n ${softflowd_log_numfiles} -s ${softflowd_log_minsize} -d \
        -z ${softflowd_log_complevel} -m 644 -o @l_rusr@ -g @l_rgrp@ \
        -P "${softflowd_log_prolog}" \
        -E "${softflowd_log_epilog} && rc softflowd restart" \
        @l_prefix@/var/softflowd/softflowd.log

