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

%config
    jabberd_enable="$openpkg_rc_def"
    jabberd_hostname=`hostname`
    jabberd_daemons="c2s resolver router s2s sm"
    jabberd_cfgfile="@l_prefix@/etc/jabberd/jabberd.cfg"
    jabberd_log_prolog="true"
    jabberd_log_epilog="true"
    jabberd_log_numfiles="10"
    jabberd_log_minsize="1M"
    jabberd_log_complevel="9"

%common
    jabberd_signal () {
        local retcode=0
        local daemons=
        for daemons in $jabberd_daemons; do
            [ -f @l_prefix@/var/jabberd/pid/${daemons}.pid ] \
            && kill -$1 `cat @l_prefix@/var/jabberd/pid/${daemons}.pid`
            retcode=$(($retcode+$?))
        done
        return $retcode
    }

%status -u @l_nusr@ -o
    jabberd_usable="unknown"
    jabberd_active="no"
    rcService jabberd enable yes && \
        jabberd_signal 0 && jabberd_active="yes"
    echo "jabberd_enable=\"$jabberd_enable\""
    echo "jabberd_usable=\"$jabberd_usable\""
    echo "jabberd_active=\"$jabberd_active\""

%start -u @l_nusr@
    rcService jabberd enable yes || exit 0
    rcService jabberd active yes && exit 0
    @l_prefix@/bin/jabberd -b -c $jabberd_cfgfile

%stop -u @l_nusr@
    rcService jabberd enable yes || exit 0
    rcService jabberd active no && exit 0
    jabberd_signal TERM
    sleep 2
    for daemons in $jabberd_daemons; do
        rm -f @l_prefix@/var/jabberd/pid/${daemons}.pid
    done

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

%daily -u @l_susr@
    rcService jabberd enable yes || exit 0
    logfiles=
    for daemons in $jabberd_daemons; do
        logfiles="$logfiles @l_prefix@/var/jabberd/log/$daemons.log"
    done
    shtool rotate -f \
        -n ${jabberd_log_numfiles} -s ${jabberd_log_minsize} -d \
        -z ${jabberd_log_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \
        -P "${jabberd_log_prolog}" \
        -E "${jabberd_log_epilog}; rc jabberd restart" \
        $logfiles

