#!/bin/bash

# run a syslog daemon

if type -p rsyslogd >/dev/null ; then
        ##exec rsyslogd -c3 -n -i /var/run/rsyslogd.pid -f /etc/rsyslog.conf
        exec rsyslogd  -n -i /var/run/rsyslogd.pid -f /etc/rsyslog.conf
elif type -p syslog-ng >/dev/null ; then
    # need get_version and version_newer functions
    . /usr/share/rear/lib/layout-functions.sh

    ng_version=$(get_version syslog-ng --version)
    if version_newer "$ng_version" "3" ; then
        ### Update the config file version to the actually used version
        sed -i "s/VERSION/${ng_version%.*}/" /etc/syslog-ng-v3.conf
        exec syslog-ng -p /var/run/syslog-ng.pid -f /etc/syslog-ng-v3.conf -F --no-caps
    else
        klogd -c 1 -x
        exec syslog-ng -p /var/run/syslog-ng.pid -f /etc/syslog-ng.conf -F
    fi
elif type -p syslogd >/dev/null ; then
    klogd -c 1 -x
    exec syslogd -f /etc/syslog.conf -n
else
    ### no syslog, so just keep running a loop
    while true ; do
        sleep 10
    done
fi
