Newer
Older
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
#!/bin/sh
###############################################################################
# Written by Chris Dunlap <cdunlap@llnl.gov>.
# Copyright (C) 2007-2013 Lawrence Livermore National Security, LLC.
# Copyright (C) 2002-2007 The Regents of the University of California.
# UCRL-CODE-155910.
###############################################################################
# chkconfig: - 66 33
# description: MUNGE Uid 'N' Gid Emporium authentication service
###############################################################################
### BEGIN INIT INFO
# Provides: munge
# Required-Start: $local_fs $remote_fs $network $time
# Required-Stop: $local_fs $remote_fs
# Should-Start: $named $syslog
# Should-Stop: $named $syslog
# Default-Start:
# Default-Stop:
# Short-Description: MUNGE Uid 'N' Gid Emporium authentication service
# Description: MUNGE (MUNGE Uid 'N' Gid Emporium) is a highly scalable
# authentication service for creating and validating
# credentials.
### END INIT INFO
###############################################################################
unset SERVICE_NAME DAEMON_EXEC DAEMON_ARGS CONFIG PIDFILE NICE USER GROUP \
SIGHUP_RELOAD VARRUNDIR
prefix="{{ munge_dir }}"
exec_prefix="${prefix}"
sbindir="${exec_prefix}/sbin"
sysconfdir="${prefix}/etc"
localstatedir="${prefix}/var"
SERVICE_NAME="MUNGE"
DAEMON_EXEC="$sbindir/munged"
DAEMON_ARGS="-S ${localstatedir}/run/munge/munge.socket.2"
#CONFIG=#_NOT_SUPPORTED_#
PIDFILE="$localstatedir/run/munge/munged.pid"
#NICE=
USER="munge"
GROUP="munge"
#SIGHUP_RELOAD=#_NOT_SUPPORTED_#
VARRUNDIR="$localstatedir/run/munge"
###############################################################################
service_init ()
{
# Determine the system type and initialize the environment.
#
# Note that the shell positional parameters must be preserved when calling
# this function in order for SuSE to initialize its environment properly.
##
PATH=/sbin:/usr/sbin:/bin:/usr/bin
INIT_NAME="`basename \"$0\" .init | sed 's/^[SK][0-9][0-9]*//'`"
DAEMON_NAME="`basename \"$DAEMON_EXEC\"`"
SIGTERM_TIMEOUT="3"
STATUS=0
# Read configuration defaults to override variables:
# $CONFIG, $DAEMON_ARGS, $PIDFILE, $USER, $NICE, $SIGHUP_RELOAD
##
for dir in "$sysconfdir/default" "$sysconfdir/sysconfig"; do
[ -r "$dir/$INIT_NAME" ] && . "$dir/$INIT_NAME"
done
[ -z "$DAEMON_ARGS" -a -n "$OPTIONS" ] && DAEMON_ARGS="$OPTIONS"
[ "`id | sed 's/^uid=\([0-9]*\).*/\1/'`" -ne 0 ] && unset USER
expr -- "$NICE" : '[0-9]*$' >/dev/null 2>&1 && NICE="+$NICE"
[ -n "$SIGHUP_RELOAD" -a "$SIGHUP_RELOAD" != 0 ] \
&& RELOAD=1 || unset RELOAD
if [ -f /etc/debian_version -a -x /sbin/start-stop-daemon ]; then
SYSTEM="DEBIAN"
[ -x "$DAEMON_EXEC" ] || exit 0 # pkg removed but not purged
[ -r /etc/default/rcS ] && . /etc/default/rcS
[ -r /lib/init/vars.sh ] && . /lib/init/vars.sh
[ -r /lib/lsb/init-functions ] && . /lib/lsb/init-functions
elif [ -f /etc/redhat-release -a -r /etc/rc.d/init.d/functions ]; then
SYSTEM="REDHAT"
. /etc/rc.d/init.d/functions
RH_LOCK="/var/lock/subsys/$INIT_NAME"
elif [ -f /etc/SuSE-release -a -r /etc/rc.status ]; then
SYSTEM="SUSE"
. /etc/rc.status
rc_reset
elif [ -r /lib/lsb/init-functions ]; then
SYSTEM="LSB"
. /lib/lsb/init-functions
else
SYSTEM="OTHER"
fi
# Exit if the package has been removed.
##
[ -x "$DAEMON_EXEC" ] || exit 5 # LSB: program not installed
# Exit if the configuration has been removed.
##
[ -z "$CONFIG" -o -r "$CONFIG" ] || exit 6 # LSB: program not configured
}
service_fini ()
{
# Return the exit status.
##
case $SYSTEM in
SUSE)
rc_exit
;;
DEBIAN|REDHAT|LSB|*)
exit $STATUS
;;
esac
}
service_start ()
{
# Start the service.
#
# Required by LSB, where running "start" on a service already running should be
# considered successful.
##
log_init "Starting $SERVICE_NAME" "$DAEMON_NAME"
if [ -n "$VARRUNDIR" -a ! -d "$VARRUNDIR" ]; then
mkdir -m 755 -p "$VARRUNDIR"
[ -n "$USER" ] && chown "$USER" "$VARRUNDIR"
[ -n "$GROUP" ] && chgrp "$GROUP" "$VARRUNDIR"
fi
case $SYSTEM in
DEBIAN)
if $0 status >/dev/null 2>&1; then
STATUS=0
else
ERRMSG=`start-stop-daemon --start --quiet \
${NICE:+"--nicelevel"} ${NICE:+"$NICE"} \
${USER:+"--chuid"} ${USER:+"$USER"} \
${PIDFILE:+"--pidfile"} ${PIDFILE:+"$PIDFILE"} \
--exec "$DAEMON_EXEC" -- $DAEMON_ARGS 2>&1`
STATUS=$?
echo $ERRMSG
fi
;;
REDHAT)
if $0 status >/dev/null 2>&1; then
STATUS=0
else
daemon ${NICE:+"$NICE"} ${USER:+"--user"} ${USER:+"$USER"} \
"$DAEMON_EXEC" $DAEMON_ARGS
STATUS=$?
fi
[ $STATUS -eq 0 ] && touch "$RH_LOCK" >/dev/null 2>&1
;;
SUSE)
ERRMSG=`startproc ${NICE:+"-n"} ${NICE:+"$NICE"} \
${USER:+"-u"} ${USER:+"$USER"} \
${PIDFILE:+"-p"} ${PIDFILE:+"$PIDFILE"} \
"$DAEMON_EXEC" $DAEMON_ARGS 2>&1`
rc_status -v
STATUS=$?
;;
LSB)
if [ -n "$USER" ]; then
ERRMSG=`su "$USER" -c "/sbin/start_daemon \
${NICE:+\"-n\"} ${NICE:+\"$NICE\"} \
${PIDFILE:+\"-p\"} ${PIDFILE:+\"$PIDFILE\"} \
\"$DAEMON_EXEC\" $DAEMON_ARGS" 2>&1`
else
ERRMSG=`start_daemon ${NICE:+"-n"} ${NICE:+"$NICE"} \
${PIDFILE:+"-p"} ${PIDFILE:+"$PIDFILE"} \
"$DAEMON_EXEC" $DAEMON_ARGS 2>&1`
fi
STATUS=$?
;;
*)
if $0 status >/dev/null 2>&1; then
STATUS=0
else
[ -n "$NICE" ] && nice="nice -n $NICE"
if [ -n "$USER" ]; then
ERRMSG=`su "$USER" -c "$nice \"$DAEMON_EXEC\" $DAEMON_ARGS" 2>&1`
else
ERRMSG=`$nice "$DAEMON_EXEC" $DAEMON_ARGS 2>&1`
fi
STATUS=$?
fi
;;
esac
log_fini "$STATUS" "$ERRMSG"
}
service_stop ()
{
# Stop the service.
#
# Required by LSB, where running "stop" on a service already stopped or not
# running should be considered successful.
##
log_init "Stopping $SERVICE_NAME" "$DAEMON_NAME"
case $SYSTEM in
DEBIAN)
if ! $0 status >/dev/null 2>&1; then
STATUS=0
else
start-stop-daemon --stop --quiet \
${PIDFILE:+"--pidfile"} ${PIDFILE:+"$PIDFILE"} \
--name "$DAEMON_NAME" ${SIGTERM_TIMEOUT:+"--retry"} \
${SIGTERM_TIMEOUT:+"$SIGTERM_TIMEOUT"} >/dev/null 2>&1
STATUS=$?
fi
;;
REDHAT)
if ! $0 status >/dev/null 2>&1; then
STATUS=0
else
killproc ${PIDFILE:+"-p"} ${PIDFILE:+"$PIDFILE"} \
${SIGTERM_TIMEOUT:+"-d"} ${SIGTERM_TIMEOUT:+"$SIGTERM_TIMEOUT"} \
"$DAEMON_EXEC"
STATUS=$?
fi
[ $STATUS -eq 0 ] && rm -f "$RH_LOCK" >/dev/null 2>&1
;;
SUSE)
killproc ${PIDFILE:+"-p"} ${PIDFILE:+"$PIDFILE"} \
${SIGTERM_TIMEOUT:+"-t"} ${SIGTERM_TIMEOUT:+"$SIGTERM_TIMEOUT"} \
"$DAEMON_EXEC"
rc_status -v
;;
LSB)
killproc ${PIDFILE:+"-p"} ${PIDFILE:+"$PIDFILE"} "$DAEMON_EXEC"
STATUS=$?
;;
*)
signal_process "$DAEMON_EXEC"
rc=$?
[ $rc -eq 0 -o $rc -eq 2 ] && STATUS=0 || STATUS=1
;;
esac
log_fini "$STATUS"
[ -f "$PIDFILE" ] && rm -f "$PIDFILE"
}
service_restart ()
{
# Stop and restart the service if it is already running;
# otherwise, start the service.
#
# Required by LSB, where running "restart" on a service already stopped or not
# running should be considered successful.
##
if $0 status >/dev/null 2>&1; then
$0 stop && $0 start
else
$0 start
fi
case $SYSTEM in
SUSE)
rc_status
;;
DEBIAN|REDHAT|LSB|*)
STATUS=$?
;;
esac
}
service_try_restart ()
{
# Restart the service if it is already running.
#
# Optional for LSB, where running "try-restart" on a service already stopped or
# not running should be considered successful.
# Also known as "condrestart" by RedHat.
##
case $SYSTEM in
REDHAT)
[ -f "$RH_LOCK" ] && $0 restart || :
STATUS=$?
;;
SUSE)
$0 status >/dev/null 2>&1 && $0 restart || rc_reset
rc_status
;;
DEBIAN|LSB|*)
$0 status >/dev/null 2>&1 && $0 restart || :
STATUS=$?
;;
esac
}
service_reload ()
{
# Reload the configuration without stopping and restarting the service.
#
# Optional for LSB.
##
[ -z "$RELOAD" ] && STATUS=3 # LSB: unimplemented feature
log_init "Reloading $SERVICE_NAME" "$DAEMON_NAME"
case $SYSTEM in
DEBIAN)
if [ -n "$RELOAD" ]; then
start-stop-daemon --stop --quiet --signal HUP \
${PIDFILE:+"--pidfile"} ${PIDFILE:+"$PIDFILE"} \
--name "$DAEMON_NAME" >/dev/null 2>&1
STATUS=$?
fi
;;
REDHAT)
if [ -n "$RELOAD" ]; then
killproc ${PIDFILE:+"-p"} ${PIDFILE:+"$PIDFILE"} "$DAEMON_EXEC" -HUP
STATUS=$?
else
echo_failure
fi
;;
SUSE)
if [ -n "$RELOAD" ]; then
killproc -HUP ${PIDFILE:+"-p"} ${PIDFILE:+"$PIDFILE"} "$DAEMON_EXEC"
else
rc_failed $STATUS
fi
rc_status -v
;;
LSB)
if [ -n "$RELOAD" ]; then
killproc ${PIDFILE:+"-p"} ${PIDFILE:+"$PIDFILE"} "$DAEMON_EXEC" -HUP
STATUS=$?
fi
;;
*)
if [ -n "$RELOAD" ]; then
signal_process "$DAEMON_EXEC" "HUP"
STATUS=$?
fi
;;
esac
log_fini "$STATUS"
}
service_force_reload ()
{
# Reload the configuration if the service supports this;
# otherwise, restart the service if it is already running.
#
# Required by LSB, where running "force-reload" on a service already stopped or
# not running should be considered successful.
##
if [ -n "$RELOAD" ]; then
$0 reload
else
$0 try-restart
fi
case $SYSTEM in
SUSE)
rc_status
;;
DEBIAN|REDHAT|LSB|*)
STATUS=$?
;;
esac
}
service_status ()
{
# Print the current status of the service.
#
# Required by LSB.
##
case $SYSTEM in
REDHAT)
status ${PIDFILE:+"-p"} ${PIDFILE:+"$PIDFILE"} "$DAEMON_EXEC"
STATUS=$?
;;
SUSE)
printf "Checking for service $SERVICE_NAME: "
checkproc ${PIDFILE:+"-p"} ${PIDFILE:+"$PIDFILE"} "$DAEMON_EXEC"
rc_status -v
;;
LSB)
printf "Checking status of $SERVICE_NAME: "
pids=`pidofproc ${PIDFILE:+"-p"} ${PIDFILE:+"$PIDFILE"} \
"$DAEMON_EXEC" 2>/dev/null`
STATUS=$?
if [ $STATUS -eq 0 -a -n "$pids" ]; then
echo "running."
elif [ $STATUS -ne 0 -a -s "$PIDFILE" ]; then
echo "dead."
else
echo "stopped."
fi
;;
DEBIAN|*)
printf "Checking status of $SERVICE_NAME: "
pids=`query_pids "$DAEMON_EXEC" "$PIDFILE"`
rc=$?
if [ $rc -eq 0 -a -n "$pids" ]; then
echo "running."
STATUS=0 # LSB: program is running
elif [ $rc -ne 0 -a -s "$PIDFILE" ]; then
echo "dead."
STATUS=1 # LSB: program is dead & pidfile exists
elif [ $rc -ne 0 ]; then
echo "stopped."
STATUS=3 # LSB: program is not running
else
echo "unknown."
STATUS=4 # LSB: program status unknown
fi
;;
esac
}
query_pids ()
{
# Writes the matching PIDs to stdout.
# Returns 0 on success (ie, pids found).
##
PROCNAME="$1"
PIDFILE="$2"
if type pgrep >/dev/null 2>&1; then
pids=`pgrep -d ' ' -x "\`basename \"$PROCNAME\"\`" 2>/dev/null`
rc=$?
elif type pidof >/dev/null 2>&1; then
pids=`pidof -o $$ -x "$PROCNAME" 2>/dev/null`
rc=$?
else
pids=`(ps awx -o pid -o command || ps -e -f -o pid -o args) 2>/dev/null \
| tail +2 | egrep "( |/)$PROCNAME( |$)" | grep -v egrep \
| sed 's/ *\([0-9]*\).*/\1/' | sort -n | tr '\012' ' '`
[ -n "$pids" ] && rc=0 || rc=1
fi
unset pids_running
if [ -n "$pids" -a -r "$PIDFILE" ]; then
read pid_line < "$PIDFILE"
for pid in $pid_line; do
expr -- "$pid" : '[0-9]*$' >/dev/null 2>&1 \
&& expr -- " $pids " : ".* $pid .*" >/dev/null 2>&1 \
&& pids_running="$pids_running $pid"
done
[ -n "$pids_running" ] && pids=$pids_running
fi
echo $pids
return $rc
}
signal_process ()
{
# Returns 0 on success, 1 if kill failed, 2 if PROCNAME is not running.
##
PROCNAME="$1"
SIGNUM="$2"
pids=`query_pids "$DAEMON_EXEC" "$PIDFILE"`
[ $? -ne 0 -o -z "$pids" ] && return 2
kill ${SIGNUM:+"-$SIGNUM"} $pids >/dev/null 2>&1
[ $? -ne 0 ] && return 1
[ -n "$SIGNUM" ] && return 0
sleep 1
pids=`query_pids "$DAEMON_EXEC" "$PIDFILE"`
[ $? -ne 0 -o -z "$pids" ] && return 0
[ -z "$SIGTERM_TIMEOUT" ] && return 1
sleep "$SIGTERM_TIMEOUT"
kill -KILL $pids >/dev/null 2>&1
pids=`query_pids "$DAEMON_EXEC" "$PIDFILE"`
[ $? -ne 0 -o -z "$pids" ] && return 0
return 1
}
log_init ()
{
# Output informational message at beginning of action.
##
MESSAGE="$1"
PROCNAME="$2"
case $SYSTEM in
DEBIAN)
if [ "$VERBOSE" != no ]; then
if type log_daemon_msg >/dev/null 2>&1; then
log_daemon_msg "$MESSAGE" "$PROCNAME"
else
printf "$MESSAGE: $PROCNAME"
fi
fi
;;
REDHAT|SUSE|LSB|*)
printf "$MESSAGE: $PROCNAME"
;;
esac
}
log_fini ()
{
# Output informational/error message at end of action.
##
STATUS="$1"
ERRMSG="$2"
case $SYSTEM in
DEBIAN)
if [ "$VERBOSE" != no ]; then
if ( type log_end_msg && type log_failure_msg ) >/dev/null 2>&1; then
log_end_msg "$STATUS"
[ $STATUS -eq 0 -o -z "$ERRMSG" ] || log_failure_msg "$ERRMSG"
else
[ $STATUS -eq 0 ] && echo "." || echo " (failed)."
[ $STATUS -eq 0 -o -z "$ERRMSG" ] || echo "$ERRMSG" >&2
fi
fi
;;
REDHAT)
echo
;;
SUSE)
[ $STATUS -eq 0 -o -z "$ERRMSG" ] || echo "$ERRMSG" >&2
;;
LSB|*)
[ $STATUS -eq 0 ] && echo "." || echo " (failed)."
[ $STATUS -eq 0 -o -z "$ERRMSG" ] || echo "$ERRMSG" >&2
;;
esac
}
###############################################################################
service_init "$@"
case "$1" in
start)
service_start
;;
stop)
service_stop
;;
restart)
service_restart
;;
try-restart|condrestart)
service_try_restart
;;
reload)
service_reload
;;
force-reload)
service_force_reload
;;
status)
service_status
;;
*)
echo "Usage: `basename \"$0\"`" \
"(start|stop|restart|try-restart|reload|force-reload|status)" >&2
exit 2 # LSB: invalid or excess argument(s)
;;
esac
service_fini