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

%config
    eliasdb_enable="$openpkg_rc_def"
    eliasdb_flags=""
    eliasdb_log_prolog="true"
    eliasdb_log_epilog="true"
    eliasdb_log_numfiles="10"
    eliasdb_log_minsize="1M"
    eliasdb_log_complevel="9"

%common
    eliasdb_cfgfile="@l_prefix@/etc/eliasdb/eliasdb.config.json"
    eliasdb_pidfile="@l_prefix@/var/eliasdb/run/eliasdb.pid"
    eliasdb_logfile="@l_prefix@/var/eliasdb/log/eliasdb.log"
    eliasdb_signal () {
        [ -f $eliasdb_pidfile ] && kill -$1 `cat $eliasdb_pidfile`
    }

%status -u @l_rusr@ -o
    eliasdb_usable="unknown"
    eliasdb_active="no"
    rcService eliasdb enable yes && \
        eliasdb_signal 0 && eliasdb_active="yes"
    echo "eliasdb_enable=\"$eliasdb_enable\""
    echo "eliasdb_usable=\"$eliasdb_usable\""
    echo "eliasdb_active=\"$eliasdb_active\""

%start -u @l_rusr@
    rcService eliasdb enable yes || exit 0
    rcService eliasdb active yes && exit 0
    (   cd @l_prefix@/etc/eliasdb
        nohup @l_prefix@/sbin/eliasdb $eliasdb_flags \
            </dev/null >>$eliasdb_logfile 2>&1 &
        echo $! >$eliasdb_pidfile
    ) >/dev/null 2>&1

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

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

%daily -u @l_susr@
    rcService eliasdb enable yes || exit 0
    shtool rotate -f \
        -n ${eliasdb_log_numfiles} -s ${eliasdb_log_minsize} -d \
        -z ${eliasdb_log_complevel} -m 664 -o @l_rusr@ -g @l_rgrp@ \
        -P "${eliasdb_log_prolog}" \
        -E "${eliasdb_log_epilog}; rc eliasdb restart" \
        $eliasdb_logfile

