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

%config
    rsyslog_enable="$openpkg_rc_def"
    rsyslog_flags=""
    rsyslog_log_prolog="true"
    rsyslog_log_epilog="true"
    rsyslog_log_numfiles="10"
    rsyslog_log_minsize="1M"
    rsyslog_log_complevel="9"

%common
    rsyslog_pidfile="@l_prefix@/var/rsyslog/run/rsyslog.pid"
    rsyslog_logfile="@l_prefix@/var/rsyslog/log/rsyslog.log"
    rsyslog_signal () {
        [ -f $rsyslog_pidfile ] && kill -$1 `cat $rsyslog_pidfile`
    }

%status -u @l_susr@ -o
    rsyslog_usable="unknown"
    rsyslog_active="no"
    rcService rsyslog enable yes && \
        rsyslog_signal 0 && rsyslog_active="yes"
    echo "rsyslog_enable=\"$rsyslog_enable\""
    echo "rsyslog_usable=\"$rsyslog_usable\""
    echo "rsyslog_active=\"$rsyslog_active\""

%start -u @l_susr@
    rcService rsyslog enable yes || exit 0
    rcService rsyslog active yes && exit 0
    @l_prefix@/sbin/rsyslogd ${rsyslog_flags}

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

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

%daily -u @l_susr@
    rcService rsyslog enable yes || exit 0
    shtool rotate -f \
        -n $rsyslog_log_numfiles -s $rsyslog_log_minsize -d \
        -z $rsyslog_log_complevel -m 664 -o @l_musr@ -g @l_mgrp@ \
        -P "$rsyslog_log_prolog" \
        -E "$rsyslog_log_epilog; rc rsyslog restart" \
        $rsyslog_logfile

