1#! /bin/sh
2# /etc/init.d/sysklogd: start the system log daemon.
3
4### BEGIN INIT INFO
5# Provides:             sysklogd
6# Required-Start:       $remote_fs $time
7# Required-Stop:        $remote_fs $time
8# Should-Start:         $network
9# Should-Stop:          $network
10# Default-Start:        2 3 4 5
11# Default-Stop:         0 1 6
12# Short-Description:    System logger
13### END INIT INFO
14
15# Source function library.
16. /etc/init.d/functions
17
18PATH=/bin:/usr/bin:/sbin:/usr/sbin
19
20pidfile_syslogd=/var/run/syslogd.pid
21binpath_syslogd=/usr/sbin/syslogd
22
23test -x $binpath || exit 0
24
25# run secure by default
26SYSLOGD="-ss"
27
28test ! -r /etc/default/syslogd || . /etc/default/syslogd
29
30create_xconsole()
31{
32    # Only proceed if /dev/xconsole is used at all
33    if ! grep -q '^[^#].*/dev/xconsole' /etc/syslog.conf
34    then
35	return
36    fi
37
38    if [ ! -e /dev/xconsole ]; then
39	mknod -m 640 /dev/xconsole p
40    else
41	chmod 0640 /dev/xconsole
42    fi
43    chown root:adm /dev/xconsole
44    test ! -x /sbin/restorecon || /sbin/restorecon /dev/xconsole
45}
46
47log_begin_msg () {
48    echo -n $1
49}
50
51log_end_msg () {
52    echo $1
53}
54
55log_success_msg () {
56    echo $1
57}
58
59running()
60{
61    # No pidfile, probably no daemon present
62    #
63    if [ ! -f $pidfile ]
64    then
65	return 1
66    fi
67
68    pid=`cat $pidfile_syslogd`
69
70    # No pid, probably no daemon present
71    #
72    if [ -z "$pid" ]
73    then
74	return 1
75    fi
76
77    if [ ! -d /proc/$pid ]
78    then
79	return 1
80    fi
81
82    cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1`
83
84    # No syslogd?
85    #
86    if [ "$cmd" != "$binpath" ]
87    then
88	return 1
89    fi
90
91    return 0
92}
93
94waitpid ()
95{
96  pid=$1
97  # Give pid a chance to exit before we restart with a 5s timeout in 1s intervals
98  if [ -z "$pid" ]; then
99    return
100  fi
101  timeout=5;
102  while [ $timeout -gt 0 ]
103  do
104    timeout=$(( $timeout-1 ))
105    kill -0 $pid 2> /dev/null || break
106    sleep 1
107  done
108}
109
110case "$1" in
111  start)
112    log_begin_msg "Starting system log daemon..."
113    create_xconsole
114    start-stop-daemon --start --quiet --pidfile $pidfile_syslogd --name syslogd --startas $binpath_syslogd -- $SYSLOGD
115    log_end_msg $?
116    ;;
117  stop)
118    log_begin_msg "Stopping system log daemon..."
119    start-stop-daemon --stop --quiet --pidfile $pidfile_syslogd --name syslogd
120    log_end_msg $?
121    ;;
122  reload|force-reload)
123    log_begin_msg "Reloading system log daemon..."
124    start-stop-daemon --stop --quiet --signal 1 --pidfile $pidfile_syslogd --name syslogd
125    log_end_msg $?
126    ;;
127  restart)
128    log_begin_msg "Restarting system log daemon..."
129    pid=`cat $pidfile_syslogd 2> /dev/null`
130    start-stop-daemon --stop --retry 5 --quiet --pidfile $pidfile_syslogd --name syslogd
131    waitpid $pid
132    start-stop-daemon --start --quiet --pidfile $pidfile_syslogd --name syslogd --startas $binpath_syslogd -- $SYSLOGD
133    log_end_msg $?
134    ;;
135  reload-or-restart)
136    if running
137    then
138	$0 reload
139    else
140	$0 start
141    fi
142    ;;
143  status)
144    status syslogd
145    RETVAL=$?
146    [ $RETVAL -eq 0 ] && exit $rval
147    exit $RETVAL
148    ;;
149  *)
150    log_success_msg "Usage: /etc/init.d/sysklogd {start|stop|reload|restart|force-reload|reload-or-restart|status}"
151    exit 1
152esac
153
154exit 0
155