File: munin-node.init

package info (click to toggle)
munin 1.2.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,940 kB
  • ctags: 98
  • sloc: sh: 4,215; makefile: 452; perl: 135
file content (97 lines) | stat: -rw-r--r-- 1,525 bytes parent folder | download | duplicates (2)
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
#! /bin/sh

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/munin-node
NAME=munin-node
PIDFILE=/var/run/munin/munin-node.pid

test -f $DAEMON || exit 0

set -e

is_running() {
	if [ -e $PIDFILE ]; then
		if kill -0 $(cat $PIDFILE) &>/dev/null; then
			return 0
		fi
	elif pgrep -f "^$DAEMON\$" >/dev/null; then
		return 0
	fi
	return 1
}

stop() {
	echo -n "Stopping munin-node: "
	if ! is_running; then
		echo "not running."
		return 0
	fi
	start-stop-daemon --stop --oknodo --pidfile $PIDFILE
	sleep 1
	if is_running; then
		echo -n "waiting.."
		if ! (sleep 2; is_running); then
			echo "done."
			return 0
		fi
		echo -n "failed, trying with signals.."
		pkill -15 -f "^$DAEMON\$"
		echo -n "SIGTERM.."
		sleep 1
		if ! is_running; then
			echo "done."
			return 0
		fi
		WAIT=5
		echo -n "SIGKILL.."
		pkill -9 -f "^$DAEMON\$"
		while [ $WAIT -ge 0 ] && sleep 1; do
			if ! is_running; then
				echo "done."
				return 0
			fi
			WAIT=$(( WAIT - 1 ))
			echo -n "."
		done
		echo "FAILED!"
		exit 1
	fi
	echo "done."
}

start() {
	echo -n "Starting munin-node: "
	if is_running; then
		echo "already running."
		exit 0
	fi
	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON
	if is_running; then
		echo "done."
		return 0
	fi
	if ! (sleep 2; is_running); then
		echo "FAILED!"
		exit 1
	fi
}
	
case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart|force-reload)
  	stop
	start
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0