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

%config
    kibana_enable="$openpkg_rc_def"
    kibana_flags=""
    kibana_log_prolog="true"
    kibana_log_epilog="true"
    kibana_log_numfiles="10"
    kibana_log_minsize="1M"
    kibana_log_complevel="9"

%common
    kibana_cfgfile="@l_prefix@/etc/kibana/kibana.yml"
    kibana_pidfile="@l_prefix@/var/kibana/run/kibana.pid"
    kibana_logfile="@l_prefix@/var/kibana/log/kibana.log"
    kibana_signal () {
        [ -f $kibana_pidfile ] && kill -$1 `cat $kibana_pidfile`
    }

%status -u @l_rusr@ -o
    kibana_usable="unknown"
    kibana_active="no"
    rcService kibana enable yes && \
        kibana_signal 0 && kibana_active="yes"
    echo "kibana_enable=\"$kibana_enable\""
    echo "kibana_usable=\"$kibana_usable\""
    echo "kibana_active=\"$kibana_active\""

%start -u @l_rusr@
    rcService kibana enable yes || exit 0
    rcService kibana active yes && exit 0
    (   nohup @l_prefix@/bin/kibana serve \
            --config "$kibana_cfgfile" \
            </dev/null >>$kibana_logfile 2>&1 &
        echo $! >$kibana_pidfile
    ) >/dev/null 2>&1

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

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

