#!/bin/bash
#
# Stop all services and prepare the cluster for a TCO.
#
. /etc/init.d/functions

action $"Ensuring this member is in the Quorum:" clustat -Q
if [ $? -ne 0 ]; then
	exit 1
fi

echo
echo "WARNING: About to stop ALL services managed by Red Hat Cluster Manager."
echo "         This should only be done when maintainence is required on "
echo "         enough members to dissolve the Cluster Quorum.  This utility"
echo "         generally does not need to be run when one cluster member"
echo "         requires maintenance.  This NEVER needs to be run in two"
echo "         member clusters."
echo
echo -n "Continue [yes/NO]? "
read a
if [ "$a" != "YES" -a "$a" != "yes" ]; then
	echo
	echo Aborted.
	exit 0
fi

action $"Preparing for global service shutdown:" clusvcadm -u
if [ $? -ne 0 ]; then
	exit 1;
fi

errors=0
for s in `cludb -m services%service[0-9]+%name | cut -f2 -d=`; do
	action "Stopping service $s: " clusvcadm -q -s $s
	if [ $? -ne 0 ]; then
		exit 1
	fi
done

echo "All clustered services are stopped."

action $"Locking service managers:" clusvcadm -l
if [ $? -ne 0 ]; then
	exit 1
fi

echo 
echo $"It is now safe to shut down all cluster members.  Be advised that"
echo $"members not controlled by power switches may still reboot when "
echo $"when the cluster quorum is disbanded."
echo
exit 0
