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

%config
    sympa_enable="$openpkg_rc_def"
    sympa_log_prolog="true"
    sympa_log_epilog="true"
    sympa_log_numfiles="10"
    sympa_log_minsize="1M"
    sympa_log_complevel="9"

%common
    sympa_start () {
        for daemon in sympa archived bounced task_manager; do
            @l_prefix@/sbin/$daemon.pl
        done
    }
    sympa_signal () {
        [ -f @l_prefix@/var/sympa/run/$1.pid ] && \
        kill -$2 `cat @l_prefix@/var/sympa/run/$1.pid`
    }
    sympa_status () {
        ( status=0
        for daemon in sympa archived bounced task_manager; do
            if sympa_signal $daemon 0; then
                :
            else
                status=1
                break
            fi
        done
        exit $status )
    }
    sympa_stop () {
        for daemon in sympa archived bounced task_manager; do
            sympa_signal $daemon TERM
        done
    }

%status -u @l_rusr@ -o
    sympa_usable="unknown"
    sympa_active="no"
    rcService sympa enable yes && \
        sympa_status && sympa_active="yes"
    echo "sympa_enable=\"$sympa_enable\""
    echo "sympa_usable=\"$sympa_usable\""
    echo "sympa_active=\"$sympa_active\""

%start -p 900 -u @l_rusr@
    rcService sympa enable yes || exit 0
    rcService sympa active yes && exit 0
    sympa_start

%stop -p 100 -u @l_rusr@
    rcService sympa enable yes || exit 0
    rcService sympa active no  && exit 0
    sympa_stop
    sleep 2

%restart -u @l_rusr@
    rcService sympa enable yes || exit 0
    rcService sympa active no  && exit 0
    sympa_stop
    sleep 2
    sympa_start

%daily -u @l_susr@
    rcService sympa enable yes || exit 0
    shtool rotate -f \
        -n ${sympa_log_numfiles} -s ${sympa_log_minsize} -d \
        -z ${sympa_log_complevel} -m 664 -o @l_susr@ -g @l_mgrp@ \
        -P "${sympa_log_prolog}" \
        -E "${sympa_log_epilog}; rc sympa restart" \
        @l_prefix@/var/sympa/run/sympa.log

