aboutsummaryrefslogtreecommitdiffstats
path: root/testing/syslog-ng/syslog-ng.initd
blob: b657b81c1e7bfb800ec8ab237678f1dca6457b21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/sbin/runscript
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

extra_commands="update"
extra_started_commands="reload"

depend() {
    need hostname localmount
    before net
    provide logger
}

start() {
    [ ! -f /etc/syslog-ng/syslog.conf ] && update
    ebegin "Starting syslog-ng"
    start-stop-daemon --start --quiet --exec /usr/sbin/syslog-ng --pidfile /var/run/syslog-ng.pid
    eend $?
}

stop() {
    ebegin "Stopping syslog-ng"
    start-stop-daemon --stop --quiet --pidfile /var/run/syslog-ng.pid --exec /usr/sbin/syslog-ng
    eend $?
}

reload() {
    if [ ! -f /var/run/syslog-ng.pid ]
    then
        eerror "syslog-ng not running!"
        return 1
    fi
    ebegin "Reloading syslog-ng"
    start-stop-daemon --signal HUP --pidfile /var/run/syslog-ng.pid --exec /usr/sbin/syslog-ng
    eend $?
}

grep_syslog_conf_entries() {
    local section="$1" FN filelist
    grep -v '^#' /etc/syslog-ng/syslog-ng-${section}.std
    filelist=$(find /etc/syslog-ng/ -maxdepth 1 -type f -name "syslog-ng-${section}.*" | grep -Ev ".backup|.std|~")
    if [ $? -eq 0 ]
    then
        for FN in ${filelist}
        do
            grep -v '^#' $FN
        done
    fi
}

update() {
    local fname='/etc/syslog-ng/syslog-ng.conf'
    local f_tmp="/etc/syslog-ng/syslog-ng.conf.$$"
    for ng_std in options source destination filter log
    do
        [ -f /etc/syslog-ng/syslog-ng-${ng_std}.std ] || exit 1
    done
    {
        # create options entries
        echo "options {"
        grep_syslog_conf_entries options
        echo "};"
        # create source entries
        echo "source s_all {"
        grep_syslog_conf_entries source
        echo "};"
        # create destination entries
        grep_syslog_conf_entries destination
        # create filter entries
        grep_syslog_conf_entries filter
        # create log entries
        grep_syslog_conf_entries log
    } > $f_tmp
    cp -p $f_tmp $fname
    rm -f $f_tmp
}