summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2013-10-15 16:42:45 +1100
committerAmitay Isaacs <amitay@gmail.com>2013-10-22 14:34:04 +1100
commit1ede20925f8bfac9546d82db48d63bdbc8369d73 (patch)
treeb39aa8b0f8e84e152af52aa82dd21e435de41198
parent1e4c965f528232eb1956f55cee9a1101fb507855 (diff)
eventscripts: Clean up 20.multipathd
Reduce the complexity, including the depth of background processes. Signed-off-by: Martin Schwenke <martin@meltin.net> (This used to be ctdb commit 49f077c475b078889ff0492fe7d567a64d6cb87c)
-rwxr-xr-xctdb/config/events.d/20.multipathd101
1 files changed, 44 insertions, 57 deletions
diff --git a/ctdb/config/events.d/20.multipathd b/ctdb/config/events.d/20.multipathd
index c2956d24a1..64748dae61 100755
--- a/ctdb/config/events.d/20.multipathd
+++ b/ctdb/config/events.d/20.multipathd
@@ -15,78 +15,65 @@ service_name="multipathd"
loadconfig
-[ -z "$CTDB_MONITOR_MPDEVICES" ] && {
- exit 0
-}
+[ -n "$CTDB_MONITOR_MPDEVICES" ] || exit 0
ctdb_setup_service_state_dir
-MPFAILURE="$service_state_dir/failure"
+multipath_fail="${service_state_dir}/fail"
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
+ 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 &
- pid="$!"
- timeleft=10
-
- while [ $timeleft -gt 0 ]; do
- timeleft=$(($timeleft - 1))
-
- # see if the process still exists
- 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
+ # 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
- fi
+ 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
- [ "$?" = "0" ] || {
- echo 20.multipathd: monitoring of multipathing failed
- exit 1
- }
- exit 0
+ multipathd_check || die "multipath monitoring failed"
;;
*)