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

%config
    emitter_enable="$openpkg_rc_def"
    emitter_flags=""
    emitter_log_prolog="true"
    emitter_log_epilog="true"
    emitter_log_numfiles="10"
    emitter_log_minsize="1M"
    emitter_log_complevel="9"

%common
    emitter_cfgfile="@l_prefix@/etc/emitter/emitter.conf"
    emitter_pidfile="@l_prefix@/var/emitter/run/emitter.pid"
    emitter_logfile="@l_prefix@/var/emitter/log/emitter.log"
    emitter_signal () {
        [ -f $emitter_pidfile ] && kill -$1 `cat $emitter_pidfile`
    }

%status -u @l_rusr@ -o
    emitter_usable="unknown"
    emitter_active="no"
    rcService emitter enable yes && \
        emitter_signal 0 && emitter_active="yes"
    echo "emitter_enable=\"$emitter_enable\""
    echo "emitter_usable=\"$emitter_usable\""
    echo "emitter_active=\"$emitter_active\""

%start -u @l_rusr@
    rcService emitter enable yes || exit 0
    rcService emitter active yes && exit 0
    (   GOMAXPROCS=32
        export GOMAXPROCS
        . @l_prefix@/etc/emitter/emitter.sh
        export EMITTER_LICENSE
        nohup @l_prefix@/sbin/emitter \
            -config $emitter_cfgfile \
            $emitter_flags \
        </dev/null >>$emitter_logfile 2>&1 &
        echo $! >$emitter_pidfile
    ) >/dev/null 2>&1

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

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

%daily -u @l_rusr@
    rcService emitter enable yes || exit 0
    shtool rotate -f \
        -n ${emitter_log_numfiles} -s ${emitter_log_minsize} -d \
        -z ${emitter_log_complevel} -m 664 -o @l_rusr@ -g @l_rgrp@ \
        -P "${emitter_log_prolog}" \
        -E "${emitter_log_epilog}; rc emitter restart" \
        $emitter_logfile

