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

%config
    disque_enable="$openpkg_rc_def"
    disque_log_prolog="true"
    disque_log_epilog="true"
    disque_log_numfiles="10"
    disque_log_minsize="1M"
    disque_log_complevel="9"

%common
    disque_logfile="@l_prefix@/var/disque/log/disque.log"
    disque_pidfile="@l_prefix@/var/disque/run/disque.pid"
    disque_signal () {
        [ -f $disque_pidfile ] && kill -$1 `cat $disque_pidfile`
    }

%status -u @l_rusr@ -o
    disque_usable="unknown"
    disque_active="no"
    rcService disque enable yes && \
        disque_signal 0 && disque_active="yes"
    echo "disque_enable=\"$disque_enable\""
    echo "disque_usable=\"$disque_usable\""
    echo "disque_active=\"$disque_active\""

%start -u @l_rusr@
    rcService disque enable yes || exit 0
    rcService disque active yes && exit 0
    @l_prefix@/bin/disque-server @l_prefix@/etc/disque/disque.conf

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

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

%daily -u @l_rusr@
    rcService disque enable yes || exit 0
    shtool rotate -f \
        -n ${disque_log_numfiles} -s ${disque_log_minsize} -d \
        -z ${disque_log_complevel} -m 664 -o @l_susr@ -g @l_mgrp@ \
        -P "${disque_log_prolog}" \
        -E "${disque_log_epilog}; rc disque restart" \
        $disque_logfile

