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

%config
    webdis_enable="$openpkg_rc_def"
    webdis_log_prolog="true"
    webdis_log_epilog="true"
    webdis_log_numfiles="10"
    webdis_log_minsize="1M"
    webdis_log_complevel="9"

%common
    webdis_logfile="@l_prefix@/var/webdis/log/webdis.log"
    webdis_pidfile="@l_prefix@/var/webdis/run/webdis.pid"
    webdis_signal () {
        [ -f $webdis_pidfile ] && kill -$1 `cat $webdis_pidfile`
    }

%status -u @l_rusr@ -o
    webdis_usable="unknown"
    webdis_active="no"
    rcService webdis enable yes && \
        webdis_signal 0 && webdis_active="yes"
    echo "webdis_enable=\"$webdis_enable\""
    echo "webdis_usable=\"$webdis_usable\""
    echo "webdis_active=\"$webdis_active\""

%start -u @l_rusr@
    rcService webdis enable yes || exit 0
    rcService webdis active yes && exit 0
    ( nohup @l_prefix@/bin/webdis @l_prefix@/etc/webdis/webdis.json </dev/null >/dev/null 2>&1 &
      echo $! >$webdis_pidfile
    ) >/dev/null 2>&1

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

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

%daily -u @l_rusr@
    rcService webdis enable yes || exit 0
    shtool rotate -f \
        -n ${webdis_log_numfiles} -s ${webdis_log_minsize} -d \
        -z ${webdis_log_complevel} -m 664 -o @l_susr@ -g @l_mgrp@ \
        -P "${webdis_log_prolog}" \
        -E "${webdis_log_epilog}; rc webdis restart" \
        $webdis_logfile

