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

%config
    dalmatinerdb_enable="$openpkg_rc_def"
    dalmatinerdb_flags=""
    dalmatinerdb_log_prolog="true"
    dalmatinerdb_log_epilog="true"
    dalmatinerdb_log_numfiles="10"
    dalmatinerdb_log_minsize="1M"
    dalmatinerdb_log_complevel="9"

%common
    dalmatinerdb_pidfile="@l_prefix@/var/dalmatinerdb/run/dalmatinerdb.pid"
    dalmatinerdb_logfile="@l_prefix@/var/dalmatinerdb/log/dalmatinerdb.console.log"
    dalmatinerdb_signal () {
        [ -f $dalmatinerdb_pidfile ] && kill -$1 `cat $dalmatinerdb_pidfile`
    }

%status -u @l_rusr@ -o
    dalmatinerdb_usable="no"
    dalmatinerdb_active="no"
    rcService nats-board enable yes && \
        dalmatinerdb_signal 0 && dalmatinerdb_active="yes"
    echo "dalmatinerdb_enable=\"$dalmatinerdb_enable\""
    echo "dalmatinerdb_usable=\"$dalmatinerdb_usable\""
    echo "dalmatinerdb_active=\"$dalmatinerdb_active\""

%start -u @l_rusr@
    rcService dalmatinerdb enable yes || exit 0
    rcService dalmatinerdb active yes && exit 0
    @l_prefix@/sbin/ddb start $dalmatinerdb_flags
    @l_prefix@/sbin/ddb-admin wait-for-service metric
    @l_prefix@/sbin/ddb-admin wait-for-service even

%stop -u @l_rusr@
    rcService dalmatinerdb enable yes || exit 0
    rcService dalmatinerdb active no  && exit 0
    @l_prefix@/sbin/ddb stop

%restart -u @l_rusr@
    rcService dalmatinerdb enable yes || exit 0
    rcService dalmatinerdb active no  && exit 0
    @l_prefix@/sbin/ddb restart

%daily -u @l_rusr@
    rcService dalmatinerdb enable yes || exit 0
    shtool rotate -f \
        -n ${dalmatinerdb_log_numfiles} -s ${dalmatinerdb_log_minsize} -d \
        -z ${dalmatinerdb_log_complevel} -m 664 -o @l_rusr@ -g @l_rgrp@ \
        -P "${dalmatinerdb_log_prolog}" \
        -E "${dalmatinerdb_log_epilog}; rc dalmatinerdb restart" \
        $dalmatinerdb_logfile

