aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-extended/sysklogd/files/sysklogd
blob: 73424840ba35caf4ed290aca6b3b2b747f7bf066 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#! /bin/sh
# /etc/init.d/sysklogd: start the system log daemon.

### BEGIN INIT INFO
# Provides:             sysklogd
# Required-Start:       $remote_fs $time
# Required-Stop:        $remote_fs $time
# Should-Start:         $network
# Should-Stop:          $network
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    System logger
### END INIT INFO

# Source function library.
. /etc/init.d/functions

PATH=/bin:/usr/bin:/sbin:/usr/sbin

pidfile_syslogd=/var/run/syslogd.pid
pidfile_klogd=/var/run/klogd.pid
binpath_syslogd=/sbin/syslogd
binpath_klogd=/sbin/klogd

test -x $binpath || exit 0

test ! -r /etc/default/syslogd || . /etc/default/syslogd

create_xconsole()
{
    # Only proceed if /dev/xconsole is used at all
    if ! grep -q '^[^#].*/dev/xconsole' /etc/syslog.conf
    then
	return
    fi

    if [ ! -e /dev/xconsole ]; then
	mknod -m 640 /dev/xconsole p
    else
	chmod 0640 /dev/xconsole
    fi
    chown root:adm /dev/xconsole
    test ! -x /sbin/restorecon || /sbin/restorecon /dev/xconsole
}

log_begin_msg () {
    echo -n $1
}

log_end_msg () {
    echo $1
}

log_success_msg () {
    echo $1
}

running()
{
    # No pidfile, probably no daemon present
    #
    if [ ! -f $pidfile ]
    then
	return 1
    fi

    pid=`cat $pidfile_syslogd`

    # No pid, probably no daemon present
    #
    if [ -z "$pid" ]
    then
	return 1
    fi

    if [ ! -d /proc/$pid ]
    then
	return 1
    fi

    cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1`

    # No syslogd?
    #
    if [ "$cmd" != "$binpath" ]
    then
	return 1
    fi

    return 0
}

waitpid ()
{
  pid=$1
  # Give pid a chance to exit before we restart with a 5s timeout in 1s intervals
  if [ -z "$pid" ]; then
    return
  fi
  timeout=5;
  while [ $timeout -gt 0 ]
  do
    timeout=$(( $timeout-1 ))
    kill -0 $pid 2> /dev/null || break
    sleep 1
  done
}

case "$1" in
  start)
    log_begin_msg "Starting system log daemon..."
    create_xconsole
    start-stop-daemon --start --quiet --pidfile $pidfile_syslogd --name syslogd --startas $binpath_syslogd -- $SYSLOGD
    log_end_msg $?
    log_begin_msg "Starting kernel log daemon..."
    start-stop-daemon --start --quiet --pidfile $pidfile_klogd --name klogd --startas $binpath_klogd -- $KLOGD
    log_end_msg $?
    ;;
  stop)
    log_begin_msg "Stopping system log daemon..."
    start-stop-daemon --stop --quiet --pidfile $pidfile_syslogd --name syslogd
    log_end_msg $?
    log_begin_msg "Stopping kernel log daemon..."
    start-stop-daemon --stop --quiet --retry 3 --exec $binpath_klogd --pidfile $pidfile_klogd
    log_end_msg $?
    ;;
  reload|force-reload)
    log_begin_msg "Reloading system log daemon..."
    start-stop-daemon --stop --quiet --signal 1 --pidfile $pidfile_syslogd --name syslogd
    log_end_msg $?
    log_begin_msg "Reloading kernel log daemon..."
    pid=`cat $pidfile_klogd 2> /dev/null`
    start-stop-daemon --stop --quiet --retry 3 --exec $binpath_klogd --pidfile $pidfile_klogd
    waitpid $pid
    start-stop-daemon --start --quiet --pidfile $pidfile_klogd --name klogd --startas $binpath_klogd -- $KLOGD
    log_end_msg $?
    ;;
  restart)
    log_begin_msg "Restarting system log daemon..."
    pid=`cat $pidfile_syslogd 2> /dev/null`
    start-stop-daemon --stop --retry 5 --quiet --pidfile $pidfile_syslogd --name syslogd
    waitpid $pid
    start-stop-daemon --start --quiet --pidfile $pidfile_syslogd --name syslogd --startas $binpath_syslogd -- $SYSLOGD
    log_end_msg $?
    log_begin_msg "Reloading kernel log daemon..."
    pid=`cat $pidfile_klogd 2> /dev/null`
    start-stop-daemon --stop --quiet --retry 3 --exec $binpath_klogd --pidfile $pidfile_klogd
    waitpid $pid
    start-stop-daemon --start --quiet --pidfile $pidfile_klogd --name klogd --startas $binpath_klogd -- $KLOGD
    log_end_msg $?
    ;;
  reload-or-restart)
    if running
    then
	$0 reload
    else
	$0 start
    fi
    ;;
  status)
    status syslogd
    RETVAL=$?
    status klogd
    rval=$?
    [ $RETVAL -eq 0 ] && exit $rval
    exit $RETVAL
    ;;
  *)
    log_success_msg "Usage: /etc/init.d/sysklogd {start|stop|reload|restart|force-reload|reload-or-restart|status}"
    exit 1
esac

exit 0