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

%config
    delegate_enable="$openpkg_rc_def"
    delegate_bind="127.0.0.1"
    delegate_port="8080"
    delegate_log_prolog="true"
    delegate_log_epilog="true"
    delegate_log_numfiles="10"
    delegate_log_minsize="1M"
    delegate_log_complevel="9"

%common
    delegate_pidfile="@l_prefix@/var/delegate/delegate.pid"
    delegate_signal () {
        [ -f $delegate_pidfile ] && kill -$1 `cat $delegate_pidfile`
    }
    delegate_start () {
        @l_prefix@/sbin/delegated \
            -P${delegate_bind}${delegate_bind:+:}${delegate_port:-8080} \
            +=@l_prefix@/etc/delegate/delegated.cf
    }
    delegate_stop () {
        delegate_signal TERM
        rm -f $delegate_pidfile 2>/dev/null || true
    }

%status -u @l_rusr@ -o
    delegate_usable="unknown"
    delegate_active="no"
    rcService delegate enable yes && \
        delegate_signal 0 && delegate_active="yes"
    echo "delegate_enable=\"$delegate_enable\""
    echo "delegate_usable=\"$delegate_usable\""
    echo "delegate_active=\"$delegate_active\""

%start -u @l_rusr@
    rcService delegate enable yes || exit 0
    rcService delegate active yes && exit 0
    delegate_start

%stop -u @l_rusr@
    rcService delegate enable yes || exit 0
    rcService delegate active no  && exit 0
    delegate_stop

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

%daily -u @l_susr@
    rcService delegate enable yes || exit 0
    shtool rotate -f \
        -n ${delegate_log_numfiles} -s ${delegate_log_minsize} -d \
        -z ${delegate_log_complevel} -m 644 -o @l_rusr@ -g @l_rgrp@ \
        -P "${delegate_log_prolog}" \
        -E "${delegate_log_epilog}; rc delegate restart" \
        "@l_prefix@/var/delegate/abort.log" \
        "@l_prefix@/var/delegate/common.log" \
        "@l_prefix@/var/delegate/error.log" \
        "@l_prefix@/var/delegate/proto.log" \
        "@l_prefix@/var/delegate/trace.log"

