PageRenderTime 39ms CodeModel.GetById 33ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/ctdb/events.d/20.multipathd

http://github.com/brinkman83/bashrc
Shell | 99 lines | 69 code | 15 blank | 15 comment | 9 complexity | 8677e951ad07760d8c78e17233596c6a MD5 | raw file
 1#!/bin/sh
 2# ctdb event script for monitoring the multipath daemon
 3#
 4# Configure monitporing of multipath devices by listing the device serials
 5# in /etc/ctdb/multipathd :
 6#   CTDB_MONITOR_MPDEVICES="device1 device2 ..."
 7#
 8
 9. $CTDB_BASE/functions
10
11service_name="multipathd"
12
13loadconfig 
14
15[ -z "$CTDB_MONITOR_MPDEVICES" ] && {
16	exit 0
17}
18
19MPFAILURE=$CTDB_BASE/state/multipathd/failure
20
21multipathd_check_background()
22{
23	for DEVICE in $CTDB_MONITOR_MPDEVICES; do
24		# check that we can see all devices
25		if [ -z "`multipath -ll $DEVICE`" ]; then
26			echo Device $DEVICE not known to multipathd
27			exit 1
28		fi
29
30		# check that all devices are active
31		if [ -z "`multipath -ll $DEVICE|grep prio|grep active`" ]; then
32			echo Device $DEVICE has no active paths
33			exit 1
34		fi
35	done
36	exit 0
37}
38
39multipathd_check()
40{
41	# run the actual check in the background since the call to 
42	# multipath may block.
43	(
44	multipathd_check_background &
45	pid="$!"
46	timeleft=10
47
48	while [ $timeleft -gt 0 ]; do
49		timeleft=$(($timeleft - 1))
50
51		# see if the process still exists
52		/bin/kill -0 $pid > /dev/null 2>&1 || {
53			# it doesn't exist, grab its exit status
54			wait $pid
55			[ $? = 0 ] || {
56				echo "20.multipathd: multipath background update exited with status $?"
57				touch $MPFAILURE
58				exit 1
59			}
60			rm $MPFAILURE 2>/dev/null
61			exit 0
62		}
63		sleep 1
64	done
65	echo "20.multipathd: Callout to multipath checks hung."
66	touch $MPFAILURE
67	exit 1
68	) &
69
70	if [ -f $MPFAILURE ]; then
71		return 1
72	else
73		return 0
74	fi
75}
76
77case "$1" in
78    startup)
79	# create a state directory to keep/track the multipath device
80	# state
81	/bin/mkdir -p $CTDB_BASE/state/multipathd
82	exit 0
83	;;
84
85    monitor)
86	multipathd_check
87	[ "$?" = "0" ] || {
88		echo 20.multipathd: monitoring of multipathing failed
89		exit 1
90	}
91	exit 0
92	;;
93
94    *)
95	ctdb_standard_event_handler "$@"
96	;;
97esac
98
99exit 0