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

%config
    syslog_ng_enable="$openpkg_rc_def"
    syslog_ng_flags=""
    syslog_ng_log_prolog="true"
    syslog_ng_log_epilog="true"
    syslog_ng_log_numfiles="10"
    syslog_ng_log_minsize="1M"
    syslog_ng_log_complevel="9"
    syslog_ng_additional_logs=""

%common
    syslog_ng_cfgfile="@l_prefix@/etc/syslog-ng/syslog-ng.conf"
    syslog_ng_pidfile="@l_prefix@/var/syslog-ng/syslog-ng.pid"
    syslog_ng_signal () {
        [ -f $syslog_ng_pidfile ] && kill -$1 `cat $syslog_ng_pidfile`
    }

%status -u @l_susr@ -o
    syslog_ng_usable="unknown"
    syslog_ng_active="no"
    rcService syslog_ng enable yes && \
        syslog_ng_signal 0 && syslog_ng_active="yes"
    echo "syslog_ng_enable=\"$syslog_ng_enable\""
    echo "syslog_ng_usable=\"$syslog_ng_usable\""
    echo "syslog_ng_active=\"$syslog_ng_active\""

%start -p 100 -u @l_susr@
    rcService syslog-ng enable yes || exit 0
    rcService syslog-ng active yes && exit 0
    @l_prefix@/sbin/syslog-ng \
        -f ${syslog_ng_cfgfile} \
        -p ${syslog_ng_pidfile} \
        ${syslog_ng_flags}

%stop -p 900 -u @l_susr@
    rcService syslog-ng enable yes || exit 0
    rcService syslog-ng active no  && exit 0
    syslog_ng_signal TERM
    sleep 2
    rm -f $syslog_ng_pidfile >/dev/null 2>&1 || true

%restart -p 100 -u @l_susr@
    rcService syslog-ng enable yes || exit 0
    rcService syslog-ng active no  && exit 0
    rc syslog-ng stop start

%daily -u @l_susr@
    rcService syslog-ng enable yes || exit 0
    shtool rotate -f \
        -n ${syslog_ng_log_numfiles} -s ${syslog_ng_log_minsize} -d \
        -z ${syslog_ng_log_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \
        -P "${syslog_ng_log_prolog}" \
        -E "${syslog_ng_log_epilog}; rc syslog-ng restart" \
        @l_prefix@/var/syslog-ng/syslog-ng.log ${syslog_ng_additional_logs}

