If there's a chance that "ctdb status -Y" can return 0 but print
garbage then this function might return a false positive.
So, we do 2 things:
* Redirect stderr to >/dev/null rather than looking at it. This
minimises the chance that we will see garbage.
* Since we need at least 1 good line to decide the cluster is healthy,
we sanity check each line to esnure it starts with :[0-9].
Signed-off-by: Martin Schwenke <martin@meltin.net>
{
local out x count line
- out=$($CTDB -Y status 2>&1) || return 1
+ out=$($CTDB -Y status 2>/dev/null) || return 1
{
read x
count=0
while read line ; do
- count=$(($count + 1))
+ # We need to see valid lines if we're going to be healthy.
+ [ "${line#:[0-9]}" != "$line" ] && count=$(($count + 1))
+ # A line indicating a node is unhealthy causes failure.
[ "${line##:*:*:*1:}" != "$line" ] && return 1
done
[ $count -gt 0 ] && return $?