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

%config
    bitflu_enable="$openpkg_rc_def"
    bitflu_log_prolog="true"
    bitflu_log_epilog="true"
    bitflu_log_numfiles="10"
    bitflu_log_minsize="1M"
    bitflu_log_complevel="9"

%common
    bitflu_pidfile="@l_prefix@/var/bitflu/bitflu.pid"
    bitflu_logfile="@l_prefix@/var/bitflu/bitflu.log"
    bitflu_signal () {
        [ -f $bitflu_pidfile ] && kill -$1 `cat $bitflu_pidfile`
    }

%status -u @l_rusr@ -o
    bitflu_usable="unknown"
    bitflu_active="no"
    rcService bitflu enable yes && \
        bitflu_signal 0 && bitflu_active="yes"
    echo "bitflu_enable=\"$bitflu_enable\""
    echo "bitflu_usable=\"$bitflu_usable\""
    echo "bitflu_active=\"$bitflu_active\""

%start -u @l_rusr@
    rcService bitflu enable yes || exit 0
    rcService bitflu active yes && exit 0
    ( nohup @l_prefix@/sbin/bitflu </dev/null >$bitflu_logfile 2>/dev/null &
      echo $! >$bitflu_pidfile
    ) >/dev/null 2>&1

%stop -u @l_rusr@
    rcService bitflu enable yes || exit 0
    rcService bitflu active no  && exit 0
    bitflu_signal TERM
    sleep 2
    rm -f $bitflu_pidfile >/dev/null 2>&1 || true

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

%daily -u @l_rusr@
    rcService bitflu enable yes || exit 0
    shtool rotate -f \
        -n $bitflu_log_numfiles -s $bitflu_log_minsize -d \
        -z $bitflu_log_complevel -m 664 -o @l_rusr@ -g @l_rgrp@ \
        -P "$bitflu_log_prolog" \
        -E "$bitflu_log_epilog; rc bitflu restart" \
        $bitflu_logfile

