3
# init.d script for the Gearman worker daemon of PNP4Nagios
5
# Based on an example script for NPCD of Javier Fernandez-Sanguino
6
# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
7
# Copyright (c) 2011 Sebastian Harl <tokkee@debian.org>
10
# Provides: pnp_gearman_worker
11
# Required-Start: $network $local_fs $remote_fs
12
# Required-Stop: $network $local_fs $remote_fs
15
# Default-Start: 2 3 4 5
17
# Short-Description: PNP4Nagios Gearman worker daemon
18
# Description: Processing of Nagios' perf data in distributed setups
21
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
23
DAEMON=/usr/lib/pnp4nagios/libexec/process_perfdata.pl
24
NAME=pnp_gearman_worker
25
DESC="PNP4Nagios Gearman worker daemon"
27
PIDFILE=/var/run/pnp4nagios/$NAME.pid
29
test -x $DAEMON || exit 0
31
. /lib/lsb/init-functions
33
# Default options, these can be overriden by the information
34
# at /etc/default/$NAME
40
if [ -f /etc/default/pnp_gearman_worker ] ; then
41
. /etc/default/pnp_gearman_worker
44
if [ "x$RUN" != "xyes" ] ; then
45
echo "$NAME has been disabled in /etc/default/pnp_gearman_worker."
51
# Check if a given process pid's cmdline matches a given name
55
[ -z "$pid" ] && return 1
56
[ ! -d /proc/$pid ] && return 1
57
cmd=`cat /proc/$pid/cmdline | tr "\000" "\n" | head -n 1 | cut -d : -f 1`
58
# Is this the expected server
59
[ "$cmd" != "$name" ] && return 1
63
# Check if the process is running looking at /proc
64
# (works for all users)
66
# No pidfile, probably no daemon present
67
[ ! -f "$PIDFILE" ] && return 1
69
running_pid "$pid" $DAEMON \
70
|| running_pid "$pid" "/usr/bin/perl" || return 1
74
# Start the process using the wrapper
76
if ! perl -MGearman::Worker -e '1;' > /dev/null 2>&1 \
77
|| ! perl -MMIME::Base64 -e '1;' > /dev/null 2>&1 \
78
|| ! perl -MCrypt::Rijndael -e '1;' > /dev/null 2>&1; then
79
echo "$NAME requires the Gearman::Worker, MIME::Base64 and" >&2
80
echo "Crypt::Rijndael Perl modules. Make sure that the packages" >&2
81
echo "perl, libgearman-client-perl and libcrypt-rijndael-perl" >&2
82
echo "are installed." >&2
86
if [ -d /var/run/pnp4nagios ]; then
87
chmod 755 /var/run/pnp4nagios
88
chown nagios.nagios /var/run/pnp4nagios
90
install -d -m 755 -o nagios -g nagios /var/run/pnp4nagios
93
start_opts="--start --quiet --oknodo --pidfile $PIDFILE"
94
if [ -n "$USER" ]; then
95
start_opts="$start_opts --chuid $USER"
97
start-stop-daemon $start_opts --exec $DAEMON -- \
98
--pidfile=$PIDFILE --gearman --daemon $DAEMON_OPTS
103
# Stop the process using the wrapper
105
killproc -p $PIDFILE $DAEMON
110
# Force the process to die killing it manually
112
[ ! -e "$PIDFILE" ] && return
121
echo "Cannot kill $NAME (pid=$pid)!"
131
log_daemon_msg "Starting $DESC" "$NAME"
132
# Check if it's running first
134
log_progress_msg "apparently already running"
138
if start_server ; then
139
# NOTE: Some servers might die some time after they start,
140
# this code will detect this issue if STARTTIME is set
141
# to a reasonable value
142
[ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time
144
# It's ok, the server started and is running
147
# It is not running after we did start
151
# Either we could not start it
156
log_daemon_msg "Stopping $DESC" "$NAME"
158
# Only stop the server if we see it running
160
stop_server || errcode=$?
163
# If it's not running don't do anything
164
log_progress_msg "apparently not running"
170
# First try to stop gracefully the program
173
# If it's still running try to kill it more forcefully
174
log_daemon_msg "Stopping (force) $DESC" "$NAME"
176
force_stop || errcode=$?
180
restart|force-reload)
181
log_daemon_msg "Restarting $DESC" "$NAME"
183
stop_server || errcode=$?
184
# Wait some sensible amount, some server need this
185
[ -n "$DIETIME" ] && sleep $DIETIME
186
start_server || errcode=$?
187
[ -n "$STARTTIME" ] && sleep $STARTTIME
188
running || errcode=$?
193
log_daemon_msg "Checking status of $DESC" "$NAME"
195
log_progress_msg "running"
198
log_progress_msg "apparently not running"
205
echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2