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

%config
    rdist_enable="$openpkg_rc_def"
    rdist_log_prolog="true"
    rdist_log_epilog="true"
    rdist_log_numfiles="10"
    rdist_log_minsize="1M"
    rdist_log_complevel="9"

%common
    rdist_pidfile="@l_prefix@/var/rdist/rdist.pid"
    rdist_cfgfile="@l_prefix@/etc/rdist/rdist.conf"
    rdist_signal () {
        [ -f $rdist_pidfile ] && kill -$1 `cat $rdist_pidfile`
    }

%status -u @l_susr@ -o
    rdist_usable="unknown"
    rdist_active="no"
    rcService rdist enable yes && \
        rdist_signal 0 && rdist_active="yes"
    echo "rdist_enable=\"$rdist_enable\""
    echo "rdist_usable=\"$rdist_usable\""
    echo "rdist_active=\"$rdist_active\""

%start -u @l_susr@
    rcService rdist enable yes || exit 0
    rcService rdist active yes && exit 0
    @l_prefix@/sbin/rdist -S -D &
    echo $! >$rdist_pidfile

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

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

%daily -u @l_susr@
    rcService rdist enable yes || exit 0
    shtool rotate -f \
        -n ${rdist_log_numfiles} -s ${rdist_log_minsize} -d \
        -z ${rdist_log_complevel} -o @l_susr@ -g @l_mgrp@ -m 644 \
        -P "${rdist_log_prolog}" \
        -E "${rdist_log_epilog}; rc rdist restart" \
        @l_prefix@/var/rdist/rdist.log

