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

%config
    flowd_enable="$openpkg_rc_def"
    flowd_flags=""
    flowd_log_prolog="true"
    flowd_log_epilog="true"
    flowd_log_numfiles="10"
    flowd_log_minsize="1M"
    flowd_log_complevel="9"

%common
    flowd_logfile="@l_prefix@/var/flowd/flowd.log"
    flowd_pidfile="@l_prefix@/var/flowd/flowd.pid"
    flowd_signal () {
        [ -f $flowd_pidfile ] && kill -$1 `cat $flowd_pidfile`
    }

%status -u @l_susr@ -o
    flowd_usable="no"
    flowd_active="no"
    rcService flowd enable yes && \
        flowd_signal 0 && flowd_active="yes"
    echo "flowd_enable=\"$flowd_enable\""
    echo "flowd_usable=\"$flowd_usable\""
    echo "flowd_active=\"$flowd_active\""

%start -u @l_susr@
    rcService flowd enable yes || exit 0
    rcService flowd active yes && exit 0
    @l_prefix@/sbin/flowd $flowd_flags

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

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

%reload -u @l_susr@
    rcService flowd enable yes || exit 0
    rcService flowd active no  && exit 0
    flowd_signal HUP

%daily -u @l_susr@
    rcService flowd enable yes || exit 0
    shtool rotate -f \
        -n ${flowd_log_numfiles} -s ${flowd_log_minsize} -d \
        -z ${flowd_log_complevel} -m 644 -o @l_rusr@ -g @l_rgrp@ \
        -P "${flowd_log_prolog}" \
        -E "${flowd_log_epilog} && rc flowd reload" \
        $flowd_logfile

