CVE-2016-0771: tests/dns: Remove dependencies on env variables
[Samba.git] / ctdb / config / events.d / 20.multipathd
blob64748dae61c71eee2867d71951fc789f409e2dc0
1 #!/bin/sh
2 # ctdb event script for monitoring the multipath daemon
4 # Configure monitporing of multipath devices by listing the device serials
5 # in /etc/ctdb/multipathd :
6 # CTDB_MONITOR_MPDEVICES="device1 device2 ..."
9 [ -n "$CTDB_BASE" ] || \
10 export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD")
12 . $CTDB_BASE/functions
14 service_name="multipathd"
16 loadconfig
18 [ -n "$CTDB_MONITOR_MPDEVICES" ] || exit 0
20 ctdb_setup_service_state_dir
22 multipath_fail="${service_state_dir}/fail"
24 multipathd_check_background()
26 for _device in $CTDB_MONITOR_MPDEVICES; do
27 # Check multipath knows about the device
28 _out=$(multipath -ll "$_device")
29 if [ -z "$_out" ] ; then
30 echo "device \"${_device}\" not known to multipathd" >"$multipath_fail"
31 exit 1
34 # Check for at least 1 active path
35 if ! echo "$_out" | grep 'prio=.* status=active' >/dev/null 2>&1 ; then
36 echo "multipath device \"${_device}\" has no active paths" >"$multipath_fail"
37 exit 1
39 done
40 exit 0
43 multipathd_check()
45 # Run the actual check in the background since the call to
46 # multipath may block
47 multipathd_check_background </dev/null >/dev/null 2>&1 &
48 _pid="$!"
49 _timeleft=10
51 while [ $_timeleft -gt 0 ]; do
52 _timeleft=$(($_timeleft - 1))
54 # see if the process still exists
55 kill -0 $_pid >/dev/null 2>&1 || {
56 if wait $_pid ; then
57 return 0
58 else
59 echo -n "ERROR: "
60 cat "$multipath_fail"
61 rm -f "$multipath_fail"
62 return 1
65 sleep 1
66 done
68 echo "ERROR: callout to multipath checks hung"
69 # If hung then this probably won't work, but worth trying...
70 kill -9 $_pid >/dev/null 2>&1
71 return 1
74 case "$1" in
75 monitor)
76 multipathd_check || die "multipath monitoring failed"
80 ctdb_standard_event_handler "$@"
82 esac
84 exit 0