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

%config
    fabio_enable="$openpkg_rc_def"
    fabio_flags=""
    fabio_log_prolog="true"
    fabio_log_epilog="true"
    fabio_log_numfiles="10"
    fabio_log_minsize="1M"
    fabio_log_complevel="9"

%common
    fabio_cfgfile="@l_prefix@/etc/fabio/fabio.properties"
    fabio_pidfile="@l_prefix@/var/fabio/run/fabio.pid"
    fabio_logfile="@l_prefix@/var/fabio/log/fabio.log"
    fabio_signal () {
        [ -f $fabio_pidfile ] && kill -$1 `cat $fabio_pidfile`
    }

%status -u @l_susr@ -o
    fabio_usable="unknown"
    fabio_active="no"
    rcService fabio enable yes && \
        fabio_signal 0 && fabio_active="yes"
    echo "fabio_enable=\"$fabio_enable\""
    echo "fabio_usable=\"$fabio_usable\""
    echo "fabio_active=\"$fabio_active\""

%start -u @l_susr@
    rcService fabio enable yes || exit 0
    rcService fabio active yes && exit 0
    (   nohup @l_prefix@/sbin/fabio \
           -cfg "$fabio_cfgfile" \
           $fabio_flags \
        </dev/null >>$fabio_logfile 2>&1 &
        echo $! >$fabio_pidfile
    ) >/dev/null 2>&1

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

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

%daily -u @l_susr@
    rcService fabio enable yes || exit 0
    shtool rotate -f \
        -n ${fabio_log_numfiles} -s ${fabio_log_minsize} -d \
        -z ${fabio_log_complevel} -m 664 -o @l_susr@ -g @l_sgrp@ \
        -P "${fabio_log_prolog}" \
        -E "${fabio_log_epilog}; rc fabio restart" \
        $fabio_logfile

