#!/sbin/runscript
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-cluster/fence/files/fenced.rc,v 1.5 2005/03/25 16:06:31 xmerlin Exp $

depend() {
	use net
	need ccs cluster-manager cluster-locking-manager
}

start() {
	ebegin "Starting fence domain"
	/sbin/fence_tool join ${FENCED_OPTS}> /dev/null 2>&1
	eend $?
}

umount_gfs_filesystems() {
	local sig retry
	local remaining="$(awk '$3 == "gfs" { print $2 }' /proc/mounts)"

	if [ -n "${remaining}" ]
	then
	        sig=
	        retry=3
	        while [ -n "${remaining}" -a "${retry}" -gt 0 ]
	        do
	                if [ "${retry}" -lt 3 ]
			then
	                        ebegin "Unmounting GFS filesystems (retry)"
	                        umount ${remaining} &>/dev/null
	                        eend $? "Failed to unmount GFS filesystems this retry"
	                else
	                        ebegin "Unmounting GFS filesystems"
	                        umount ${remaining} &>/dev/null
	                        eend $? "Failed to unmount GFS filesystems"
	                fi
	                remaining="$(awk '$3 == "gfs" { print $2 }' /proc/mounts)"
	                [ -z "${remaining}" ] && break
	                /bin/fuser -k -m ${sig} ${remaining} &>/dev/null
	                sleep 5
	                retry=$((${retry} -1))
	                sig=-9
	        done
	fi
}

stop() {

	# umount GFS filesystems
	umount_gfs_filesystems
	
	ebegin "Stopping fence domain"
	/sbin/fence_tool leave > /dev/null 2>&1
	eend $?
}
