#!/bin/sh --
#
# Stop/start the cluster services on a real server.  Leaves heartbeat and
# the director services alone.  Use "service heartbeat" to control those.
#
# by BVH 12 mar 2007
#

VIP=192.168.1.250
PORTS=(80)
#PORTS=(80 443)
IPVSADM=/sbin/ipvsadm
RS=`/bin/uname -n`
STATUS0="$IPVSADM -L -n"
STATUS1="/usr/sbin/ldirectord /etc/ha.d/ldirectord.cf status"
STATUS2="/etc/ha.d/resource.d/LVSSyncDaemonSwap master status"

case "$1" in
	start)
		if [ `$STATUS0 | grep -c $VIP` -eq 1 ]; then
			if [ ! "X$2" = "X" ]; then
				RS=$2
			fi
			for i in ${PORTS[@]}; do
				echo "Adding $RS:$i to $VIP cluster..."
				$IPVSADM -e -t $VIP:$i -r $RS:$i -w 1
			done
			exec $STATUS0
		else
			echo "$VIP cluster is not managed by this host"
			exit 1
		fi
		;;
	stop)
		if [ `$STATUS0 | grep -c $VIP` -eq 1 ]; then
			if [ ! "X$2" = "X" ]; then
				RS=$2
			fi
			for i in ${PORTS[@]}; do
				echo "Removing $RS:$i from $VIP cluster..."
				echo "  ***  Please wait for all active connections to finish before stopping"
				echo "  ***  the service daemon.  Check with \"service cluster status\""
				echo
				$IPVSADM -e -t $VIP:$i -r $RS:$i -w 0
			done
			exec $STATUS0
		else
			echo "$VIP cluster is not managed by this host"
			exit 1
		fi
		;;
	status)
		$STATUS1
		$STATUS2
		$STATUS0
		exit 0
		;;
	*)
		echo "Usage: service cluster (start|stop|status) [real_server]"
		exit 1
		;;
esac

