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

%config
    janus_enable="$openpkg_rc_def"
    janus_flags=""
    janus_log_prolog="true"
    janus_log_epilog="true"
    janus_log_numfiles="10"
    janus_log_minsize="1M"
    janus_log_complevel="9"

%common
    janus_pidfile="@l_prefix@/var/janus/run/janus.pid"
    janus_logfile="@l_prefix@/var/janus/log/janus.log"
    janus_signal () {
        [ -f $janus_pidfile ] && kill -$1 `cat $janus_pidfile`
    }

%status -u @l_rusr@ -o
    janus_usable="no"
    janus_active="no"
    rcService janus enable yes && \
        janus_signal 0 && janus_active="yes"
    echo "janus_enable=\"$janus_enable\""
    echo "janus_usable=\"$janus_usable\""
    echo "janus_active=\"$janus_active\""

%start -p 100 -u @l_rusr@
    rcService janus enable yes || exit 0
    rcService janus active yes && exit 0
    @l_prefix@/bin/janus ${janus_flags}

%stop -p 900 -u @l_rusr@
    rcService janus enable yes || exit 0
    rcService janus active no  && exit 0
    janus_signal TERM
    sleep 2
    rm -f $janus_pidfile >/dev/null 2>&1 || true

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

%daily -u @l_rusr@
    rcService janus enable yes || exit 0
    shtool rotate -f \
        -n $janus_log_numfiles -s $janus_log_minsize -d \
        -z $janus_log_complevel -m 644 -o @l_rusr@ -g @l_rgrp@ \
        -P "$janus_log_prolog" \
        -E "$janus_log_epilog" \
        $janus_logfile

