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

%config
    distcc_enable="$openpkg_rc_def"
    distcc_listen="127.0.0.1"
    distcc_accept="127.0.0.1/8"
    distcc_flags=""
    distcc_log_prolog="true"
    distcc_log_epilog="true"
    distcc_log_numfiles="10"
    distcc_log_minsize="1M"
    distcc_log_complevel="9"

%common
    distcc_tmpdir="@l_prefix@/var/distcc/tmp"
    distcc_pidfile="@l_prefix@/var/distcc/run/distcc.pid"
    distcc_logfile="@l_prefix@/var/distcc/run/distcc.log"
    distcc_signal () {
        [ -f $distcc_pidfile ] && kill -$1 `cat $distcc_pidfile`
    }

%status -u @l_susr@ -o
    distcc_usable="unknown"
    distcc_active="no"
    rcService distcc enable yes && \
        distcc_signal 0 && distcc_active="yes"
    echo "distcc_enable=\"$distcc_enable\""
    echo "distcc_usable=\"$distcc_usable\""
    echo "distcc_active=\"$distcc_active\""

%start -u @l_susr@
    rcService distcc enable yes || exit 0
    rcService distcc active yes && exit 0
    flags=""
    flags="$flags --daemon"
    flags="$flags --user \"@l_rusr@\""
    flags="$flags --listen \"$distcc_listen\""
    for accept in $distcc_accept; do
        flags="$flags --allow \"$accept\""
    done
    flags="$flags --pid-file $distcc_pidfile"
    flags="$flags --log-file $distcc_logfile "
    flags="$flags $distcc_flags"
    eval TMPDIR="$distcc_tmpdir" \
        @l_prefix@/bin/distccd $flags

%stop -u @l_susr@
    rcService distcc enable yes || exit 0
    rcService distcc active no  && exit 0
    distcc_signal TERM
    sleep 2
    rm -f $distcc_pidfile >/dev/null 2>&1 || true

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

%daily -u @l_susr@
    rcService distcc enable yes || exit 0
    shtool rotate -f \
        -n ${distcc_log_numfiles} -s ${distcc_log_minsize} -d \
        -z ${distcc_log_complevel} -m 664 -o @l_susr@ -g @l_mgrp@ \
        -P "${distcc_log_prolog}" \
        -E "${distcc_log_epilog}; rc distcc restart" \
        $distcc_logfile

