summaryrefslogtreecommitdiffstats
path: root/ctdb/config/events.d/20.multipathd
blob: 091a7739b695a564c98c284eb95a6e2c2e2a805b (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
#!/bin/sh
# ctdb event script for monitoring the multipath daemon
#
# Configure monitporing of multipath devices by listing the device serials
# in /etc/ctdb/multipathd :
#   CTDB_MONITOR_MPDEVICES="device1 device2 ..."
#

. $CTDB_BASE/functions

service_name="multipathd"

loadconfig 

[ -z "$CTDB_MONITOR_MPDEVICES" ] && {
	exit 0
}

MPFAILURE=$CTDB_BASE/state/multipathd/failure

multipathd_check_background()
{
	for DEVICE in $CTDB_MONITOR_MPDEVICES; do
		# check that we can see all devices
		if [ -z "`multipath -ll $DEVICE`" ]; then
			echo Device $DEVICE not known to multipathd
			exit 1
		fi

		# check that all devices are active
		if [ -z "`multipath -ll $DEVICE|grep prio|grep active`" ]; then
			echo Device $DEVICE has no active paths
			exit 1
		fi
	done
	exit 0
}

multipathd_check()
{
	# run the actual check in the background since the call to 
	# multipath may block.
	(
	multipathd_check_background &
	pid="$!"
	timeleft=10

	while [ $timeleft -gt 0 ]; do
		timeleft=$(($timeleft - 1))

		# see if the process still exists
		/bin/kill -0 $pid > /dev/null 2>&1 || {
			# it doesn't exist, grab its exit status
			wait $pid
			[ $? = 0 ] || {
				echo "20.multipathd: multipath background update exited with status $?"
				touch $MPFAILURE
				exit 1
			}
			rm $MPFAILURE 2>/dev/null
			exit 0
		}
		sleep 1
	done
	echo "20.multipathd: Callout to multipath checks hung."
	touch $MPFAILURE
	exit 1
	) &

	if [ -f $MPFAILURE ]; then
		return 1
	else
		return 0
	fi
}

case "$1" in
    startup)
	# create a state directory to keep/track the multipath device
	# state
	/bin/mkdir -p $CTDB_BASE/state/multipathd
	exit 0
	;;

    monitor)
	multipathd_check
	[ "$?" = "0" ] || {
		echo 20.multipathd: monitoring of multipathing failed
		exit 1
	}
	exit 0
	;;

    *)
	ctdb_standard_event_handler "$@"
	;;
esac

exit 0