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

%config
    corvus_enable="$openpkg_rc_def"
    corvus_log_prolog="true"
    corvus_log_epilog="true"
    corvus_log_numfiles="10"
    corvus_log_minsize="1M"
    corvus_log_complevel="9"

%common
    corvus_cluster="@cluster@"
    corvus_cfgfile="@l_prefix@/etc/corvus/corvus.conf"
    corvus_logfile="@l_prefix@/var/corvus/log/corvus.log"
    corvus_pidfile="@l_prefix@/var/corvus/run/corvus.pid"
    corvus_signal () {
        [ -f $corvus_pidfile ] && kill -$1 `cat $corvus_pidfile`
    }

%status -u @l_rusr@ -o
    corvus_usable="unknown"
    corvus_active="no"
    rcService corvus enable yes && \
        corvus_signal 0 && corvus_active="yes"
    echo "corvus_enable=\"$corvus_enable\""
    echo "corvus_usable=\"$corvus_usable\""
    echo "corvus_active=\"$corvus_active\""

%start -u @l_rusr@
    rcService corvus enable yes || exit 0
    rcService corvus active yes && exit 0
    (   nohup @l_prefix@/sbin/corvus \
            $corvus_cfgfile \
            >>$corvus_logfile 2>&1 &
        echo $! >$corvus_pidfile
    ) </dev/null >/dev/null 2>&1

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

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

%daily -u @l_rusr@
    rcService corvus enable yes || exit 0
    shtool rotate -f \
        -n ${corvus_log_numfiles} -s ${corvus_log_minsize} -d \
        -z ${corvus_log_complevel} -m 664 -o @l_susr@ -g @l_mgrp@ \
        -P "${corvus_log_prolog}" \
        -E "${corvus_log_epilog}; rc corvus restart" \
        $corvus_logfile

