summaryrefslogtreecommitdiffstats
path: root/ctdb/config/events.d/20.multipathd
blob: 64748dae61c71eee2867d71951fc789f409e2dc0 (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
#!/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 ..."
#

[ -n "$CTDB_BASE" ] || \
    export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD")

. $CTDB_BASE/functions

service_name="multipathd"

loadconfig 

[ -n "$CTDB_MONITOR_MPDEVICES" ] || exit 0

ctdb_setup_service_state_dir

multipath_fail="${service_state_dir}/fail"

multipathd_check_background()
{
    for _device in $CTDB_MONITOR_MPDEVICES; do
	# Check multipath knows about the device
	_out=$(multipath -ll "$_device")
	if [ -z "$_out" ] ; then
	    echo "device \"${_device}\" not known to multipathd" >"$multipath_fail"
	    exit 1
	fi

	# Check for at least 1 active path
	if ! echo "$_out" | grep 'prio=.* status=active' >/dev/null 2>&1 ; then
	    echo "multipath device \"${_device}\" has no active paths" >"$multipath_fail"
	    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 </dev/null >/dev/null 2>&1 &
    _pid="$!"
    _timeleft=10

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

	# see if the process still exists
	kill -0 $_pid >/dev/null 2>&1 || {
	    if wait $_pid ; then
		return 0
	    else
		echo -n "ERROR: "
		cat "$multipath_fail"
		rm -f "$multipath_fail"
		return 1
	    fi
	}
	sleep 1
    done

    echo "ERROR: callout to multipath checks hung"
    # If hung then this probably won't work, but worth trying...
    kill -9 $_pid >/dev/null 2>&1
    return 1
}

case "$1" in
    monitor)
	multipathd_check || die "multipath monitoring failed"
	;;

    *)
	ctdb_standard_event_handler "$@"
	;;
esac

exit 0