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

%config
    spread_enable="$openpkg_rc_def"
    spread_log_prolog="true"
    spread_log_epilog="true"
    spread_log_numfiles="10"
    spread_log_minsize="1M"
    spread_log_complevel="9"

%common
    spread_pidfile="@l_prefix@/var/spread/spread.pid"
    spread_signal () {
        [ -f $spread_pidfile ] && kill -$1 `cat $spread_pidfile`
    }

%status -u @l_susr@ -o
    spread_usable="no"
    spread_active="no"
    rcService spread enable yes && \
        spread_signal 0 && spread_active="yes"
    echo "spread_enable=\"$spread_enable\""
    echo "spread_usable=\"$spread_usable\""
    echo "spread_active=\"$spread_active\""

%start -u @l_susr@
    rcService spread enable yes || exit 0
    rcService spread active yes && exit 0
    @l_prefix@/sbin/spread &
    echo $! >$spread_pidfile

%stop -u @l_susr@
    rcService spread enable yes || exit 0
    rcService spread active no && exit 0
    spread_signal TERM
    rm -f $spread_pidfile 2>/dev/null || true

%restart -u @l_susr@
    rcService spread enable yes || exit 0
    rcService spread active no && exit 0
    rc spread stop
    sleep 2
    rc spread start

%daily -u @l_susr@
    rcService spread enable yes || exit 0
    shtool rotate -f \
        -n ${spread_log_numfiles} -s ${spread_log_minsize} -d \
        -z ${spread_log_complevel} -o @l_rusr@ -g @l_mgrp@ -m 644 \
        -P "${spread_log_prolog}" \
        -E "${spread_log_epilog}; rc spread restart" \
        @l_prefix@/var/spread/spread.log

