1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00
samba-mirror/ctdb/config/events.d/20.multipathd
Martin Schwenke b208ae73d1 ctdb-scripts: Avoid shellcheck warning SC2154 (unassigned variables)
SC2154: VAR is referenced but not assigned.

Change ctdb_setup_service_state_dir(), ctdb_get_pnn() and
ctdb_get_ip_address() to print the value so it can be assigned to a
variable.  The performance gain from avoiding the sub-shells when
calling these functions is close to zero.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2016-07-21 02:24:26 +02:00

83 lines
1.8 KiB
Bash
Executable File

#!/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" ] || \
CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD")
. "${CTDB_BASE}/functions"
# service_name is used by various functions
# shellcheck disable=SC2034
service_name="multipathd"
loadconfig
[ -n "$CTDB_MONITOR_MPDEVICES" ] || exit 0
service_state_dir=$(ctdb_setup_service_state_dir) || exit $?
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"
;;
esac
exit 0