#! /bin/sh
#
# cman        This starts and stops the CMAN cluster subsystems
#
# chkconfig: 345 60 19
# description: CMAN Cluster subsystems

# Source function library.
. /etc/rc.d/init.d/functions

# Get Configuration variables
[ -f  /etc/sysconfig/cman ] && . /etc/sysconfig/cman

# Need a cluster name
if [ -z "$CLUSTER_NAME" ]
then
  echo "Cluster services not started, no cluster name"
  exit 1
fi

set -e

case "$1" in
    start)
	echo -n $"Starting cluster services"
	ccsd
	sleep 1
	modprobe cman
	modprobe dlm
	modprobe lock_harness
	modprobe gfs
	modprobe lock_dlm
	cman_tool join -c $CLUSTER_NAME
	fenced
	clvmd
	lvm vgchange -aly &
	touch /var/lock/subsys/cman
	echo
        ;;

    stop)
	echo -n $"Stopping cluster services"
	umount -a -tgfs
	grep "blocked" /proc/cluster/status > /dev/null
	[ $? = 1 ] && lvm vgchange -aln --ignorelockingfailure
	killproc clvmd || true
	killproc ccsd || true
	fence_tool leave || true
	sleep 3
	cman_tool leave remove
	rm -f /var/lock/subsys/cman
	echo
	;;

    status)
	cat /proc/cluster/status
	;;
    *)
 	echo "Usage cluster {start|stop|status}"
	exit 1;
	;;
esac

exit 0
