]> TLD Linux GIT Repositories - packages/syslog-ng.git/blob - syslog-ng.init
- updated version
[packages/syslog-ng.git] / syslog-ng.init
1 #!/bin/sh
2 #
3 # syslog        Starts syslog-ng (syslogd replacement).
4 #
5 # chkconfig:    2345 17 83
6 # description:  Syslog is the facility by which many daemons use to log \
7 #               messages to various system log files. It is a good idea to \
8 #               always run syslog.
9
10 # Source function library
11 . /etc/rc.d/init.d/functions
12
13 # Get service config
14 if [ -f /etc/sysconfig/syslog-ng ]; then
15         . /etc/sysconfig/syslog-ng
16 fi
17
18 # configtest itself
19 # must return non-zero if check failed
20 # output is discarded if checkconfig is ran without details
21 configtest() {
22         syslog-ng $OPTIONS -F -s -p /var/run/syslog-ng-syntaxcheck.pid
23         return $?
24 }
25
26 # wrapper for configtest
27 checkconfig() {
28         local details=${1:-0}
29
30         if [ $details = 1 ]; then
31                 # run config test and display report (status action)
32                 show "Checking %s configuration" "syslog-ng"; busy
33                 local out
34                 out=$(configtest 2>&1)
35                 RETVAL=$?
36                 if [ $RETVAL = 0 ]; then
37                         ok
38                 else
39                         fail
40                 fi
41                 [ "$out" ] && echo >&2 "$out"
42         else
43                 # run config test and abort with nice message if failed
44                 # (for actions checking status before action).
45                 configtest >/dev/null 2>&1
46                 RETVAL=$?
47                 if [ $RETVAL != 0 ]; then
48                         show "Checking %s configuration" "syslog-ng"; fail
49                         nls 'Configuration test failed. See details with %s "checkconfig"' $0
50                         exit $RETVAL
51                 fi
52         fi
53 }
54
55 start() {
56         # Check if the service is already running?
57         if [ -f /var/lock/subsys/syslog-ng ]; then
58                 msg_already_running "syslog-ng"
59                 return
60         fi
61
62         msg_starting "syslog-ng"
63         daemon @@SBINDIR@@/syslog-ng -f /etc/syslog-ng/syslog-ng.conf --worker-threads=1024 $OPTIONS
64         RETVAL=$?
65         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/syslog-ng
66 }
67
68 stop() {
69         if [ ! -f /var/lock/subsys/syslog-ng ]; then
70                 msg_not_running "syslog-ng"
71                 return
72         fi
73
74         msg_stopping "syslog-ng"
75         killproc syslog-ng
76         rm -f /var/lock/subsys/syslog-ng >/dev/null 2>&1
77 }
78
79 condrestart() {
80         if [ ! -f /var/lock/subsys/syslog-ng ]; then
81                 msg_not_running "syslog-ng"
82                 RETVAL=$1
83                 return
84         fi
85
86         checkconfig
87         stop
88         start
89 }
90
91 reload() {
92         if [ ! -f /var/lock/subsys/syslog-ng ]; then
93                 msg_not_running "syslog-ng"
94                 RETVAL=7
95                 return
96         fi
97
98         checkconfig
99         msg_reloading "syslog-ng"
100         killproc syslog-ng -HUP
101         RETVAL=$?
102 }
103
104 flush_logs() {
105         if [ -f /var/lock/subsys/syslog-ng ]; then
106                 checkconfig
107                 msg_reloading "syslog-ng"
108                 killproc syslog-ng -HUP
109                 RETVAL=$?
110         else
111                 msg_not_running "syslog-ng"
112                 RETVAL=7
113         fi
114 }
115
116 RETVAL=0
117 # See how we were called.
118 case "$1" in
119   start)
120         configtest
121         start
122         ;;
123   stop)
124         stop
125         ;;
126   restart)
127         configtest
128         stop
129         start
130         ;;
131   try-restart)
132         condrestart 0
133         ;;
134   reload|force-reload)
135         reload
136         ;;
137   flush-logs)
138         flush_logs
139         ;;
140   checkconfig|configtest)
141         checkconfig 1
142         ;;
143   status)
144         status syslog-ng
145         exit $?
146         ;;
147   *)
148         msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status|checkconfig|flush-logs}"
149         exit 3
150 esac
151
152 exit $RETVAL