This is the mail archive of the cluster-cvs@sourceware.org mailing list for the cluster.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

cluster: STABLE3 - cman init: major clean up of shutdown sequence


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=c062d7a1a908bdd35f9b7dfd2fdf67f7600dcc9e
Commit:        c062d7a1a908bdd35f9b7dfd2fdf67f7600dcc9e
Parent:        7a15c284c78688473f3d3eacdbd0dc9a5a131a87
Author:        Fabio M. Di Nitto <fdinitto@redhat.com>
AuthorDate:    Thu Mar 26 11:38:47 2009 +0100
Committer:     Fabio M. Di Nitto <fdinitto@redhat.com>
CommitterDate: Fri Mar 27 20:05:46 2009 +0100

cman init: major clean up of shutdown sequence

add stop_daemon function as common way to stop a daemon.
Make it so to accomodate all sorts of requirements (such
as attempt N times to stop before giving up).

move all the stop_ functions right underneath the start_
equivalent.

rename stop_fence to leave_fence_domain.

remove stop_daemons in favour of single functions.

clean stop function to be < 80 cols.

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
---
 cman/init.d/cman.in |  237 +++++++++++++++++++++++++++++----------------------
 1 files changed, 136 insertions(+), 101 deletions(-)

diff --git a/cman/init.d/cman.in b/cman/init.d/cman.in
index 9cf1360..09e0580 100644
--- a/cman/init.d/cman.in
+++ b/cman/init.d/cman.in
@@ -190,6 +190,27 @@ start_daemon()
 	return 0
 }
 
+stop_daemon()
+{
+	daemon=$1
+	shift
+	maxretries=$1
+
+	[ -z "$maxretries" ] && maxretries=1
+	retries=0
+
+	while status $daemon > /dev/null 2>&1 && \
+		[ $retries -lt $maxretries ]; do
+
+		errmsg=$( pkill -TERM $daemon ) || return 1
+		sleep 1
+		((retries++))
+	done
+
+	status $daemon > /dev/null 2>&1 && return 1
+	return 0
+}
+
 ### check functions (enable/disable) (on/off)
 
 mtab_configfs()
@@ -376,6 +397,12 @@ load_kernel_modules()
 	return 0
 }
 
+unload_kernel_modules()
+{
+	/sbin/modprobe -r lock_dlm > /dev/null 2>&1 || true
+	/sbin/modprobe -r dlm > /dev/null 2>&1 || true
+}
+
 start_configfs()
 {
 	if ! mtab_configfs; then
@@ -385,6 +412,19 @@ start_configfs()
 	return 0
 }
 
+stop_configfs()
+{
+	if mtab_configfs && [ -z "$(ls -1 /sys/kernel/config)" ]; then
+		errmsg=$( /bin/umount /sys/kernel/config 2>&1 )
+		if [ $? -ne 0 ]; then
+			return 1
+		fi
+		/sbin/modprobe -r configfs > /dev/null 2>&1 || true
+	fi
+	return 0
+}
+
+
 set_networking_params()
 {
 	if [ ! -f  /proc/sys/net/core/rmem_default ]; then
@@ -417,6 +457,15 @@ start_cman()
 	return 0
 }
 
+stop_cman()
+{
+	if cman_running; then
+		errmsg=$( @SBINDIR@/cman_tool -t $CMAN_SHUTDOWN_TIMEOUT \
+			-w leave $cmanremove 2>&1 ) || return 1
+	fi
+	return 0
+}
+
 unfence_self()
 {
 	fence_node -U > /dev/null 2>&1
@@ -430,36 +479,72 @@ start_qdiskd()
 	return $?
 }
 
+stop_qdiskd()
+{
+	stop_daemon qdiskd 5
+	return $?
+}
+
 start_groupd()
 {
 	start_daemon groupd 
 	return $?
 }
 
+stop_groupd()
+{
+	stop_daemon groupd
+	return $?
+}
+
 start_fenced()
 {
 	start_daemon fenced
 	return $?
 }
 
+stop_fenced()
+{
+	stop_daemon fenced
+	return $?
+}
+
 start_dlm_controld()
 {
 	start_daemon dlm_controld
 	return $?
 }
 
+stop_dlm_controld()
+{
+	stop_daemon dlm_controld
+	return $?
+}
+
 start_gfs_controld()
 {
 	start_daemon gfs_controld
 	return $?
 }
 
+stop_gfs_controld()
+{
+	stop_daemon gfs_controld
+	return $?
+}
+
 start_cmannotifyd()
 {
 	start_daemon cmannotifyd
 	return $?
 }
 
+stop_cmannotifyd()
+{
+	stop_daemon cmannotifyd
+	return $?
+}
+
 join_fence_domain()
 {
 	if ! @SBINDIR@/cman_tool status | grep Flags | grep 2node > /dev/null 2>&1; then
@@ -473,12 +558,27 @@ join_fence_domain()
 	return 0
 }
 
+leave_fence_domain()
+{
+	if status fenced > /dev/null 2>&1; then
+		@SBINDIR@/fence_tool leave -w 10 > /dev/null 2>&1
+		return $?
+	fi
+	return 0
+}
+
 start_fence_xvmd()
 {
 	start_daemon fence_xvmd "$FENCE_XVMD_OPTS"
 	return $?
 }
 
+stop_fence_xvmd()
+{
+	stop_daemon fence_xvmd 
+	return $?
+}
+
 start()
 {
 	echo "Starting cluster: "
@@ -546,113 +646,53 @@ start()
 	return 0
 }
 
-stop_configfs()
-{
-	if mtab_configfs && [ -z "$(ls -1 /sys/kernel/config)" ]; then
-		errmsg=$( /bin/umount /sys/kernel/config 2>&1 )
-		if [ $? -ne 0 ]; then
-			return 1
-		fi
-		/sbin/modprobe -r configfs > /dev/null 2>&1 || true
-	fi
-	return 0
-}
-
-stop_cman()
-{
-	if cman_running; then
-		errmsg=$( @SBINDIR@/cman_tool -t $CMAN_SHUTDOWN_TIMEOUT \
-			-w leave $cmanremove 2>&1 ) || return 1
-	fi
-	return 0 # all ok
-}
-
-stop_daemons()
+stop()
 {
-	if status gfs_controld > /dev/null 2>&1; then
-		errmsg=$(pkill -TERM gfs_controld) || return 1
-	fi
-	if status dlm_controld > /dev/null 2>&1; then
-		errmsg=$(pkill -TERM dlm_controld) || return 1
-	fi
-	if status fenced > /dev/null 2>&1; then
-		errmsg=$(pkill -TERM fenced) || return 1
-	fi
-	if status groupd > /dev/null 2>&1; then
-		errmsg=$(pkill -TERM groupd) || return 1
-	fi
-	return 0 # all ok
-}
+	echo "Stopping cluster: "
 
-stop_cmannotifyd()
-{
-	if status cmannotifyd > /dev/null 2>&1; then
-		errmsg=$(pkill -TERM cmannotifyd) || return 1
-	fi
-	return 0
-}
+	runwrap stop_fence_xvmd \
+		fence_xvmd_enabled \
+		"Stopping virtual machine fencing host"
 
-stop_qdiskd()
-{
-	retries=0
+	runwrap leave_fence_domain \
+		fence_join_enabled \
+		"Leaving fence domain"
 
-	while status qdiskd > /dev/null 2>&1 && [ $retries -lt 5 ]; do
-		errmsg=$(pkill -TERM qdiskd) || return 1
-		sleep 1
-		((retries++))
-	done
-	if status qdiskd > /dev/null 2>&1; then
-		return 1
-	fi
-	return 0
-}
+	runwrap stop_gfs_controld \
+		none \
+		"Stopping gfs_controld"
 
-stop_fence()
-{
-	if ! fence_join_enabled; then
-		return 0
-	fi
+	runwrap stop_dlm_controld \
+		none \
+		"Stopping dlm_controld"
 
-	if status fenced > /dev/null 2>&1; then
-		@SBINDIR@/fence_tool leave -w 10 > /dev/null 2>&1
-		return $?
-	fi
-	return 0 # all ok
-}
+	runwrap stop_fenced \
+		none \
+		"Stopping fenced"
 
-stop_fence_xvmd()
-{
-	if ! fence_xvmd_enabled; then
-		return 0
-	fi
+	runwrap stop_groupd \
+		none \
+		"Stopping groupd"
 
-	if status fence_xvmd > /dev/null 2>&1; then
-		errmsg=$(pkill -TERM fence_xvmd) || return 1
-		sleep 1 # A bit of time for fenced to exit
-	fi
+	runwrap stop_qdiskd \
+		none \
+		"Stopping qdiskd"
 
-	status fence_xvmd
-	return $?
-}
+	runwrap stop_cman \
+		none \
+		"Stopping cman"
 
-unload_modules()
-{
-	/sbin/modprobe -r lock_dlm > /dev/null 2>&1 || true
-	/sbin/modprobe -r dlm > /dev/null 2>&1 || true
-}
+	runwrap stop_cmannotifyd \
+		cmannotifyd_enabled \
+		"Stopping cmannotifyd"
 
-stop()
-{
-	echo "Stopping cluster: "
+	runwrap unload_kernel_modules \
+		none \
+		"Unloading kernel modules"
 
-	runwrap stop_fence_xvmd none "Stopping virtual machine fencing host"
-	runwrap stop_fence none "Stopping fencing"
-	runwrap stop_daemons none "Stopping daemons"
-	runwrap stop_qdiskd none "Stopping qdiskd"
-	runwrap stop_cman none "Stopping cman"
-	runwrap stop_cmannotifyd none "Stopping cmannotifyd"
-	runwrap unload_modules none "Unloading modules"
-	runwrap stop_configfs none "Unmounting configfs"
+	runwrap stop_configfs \
+		none \
+		"Unmounting configfs"
 
 	return 0
 }
@@ -693,12 +733,7 @@ start)
 ;;
 stop)
 	cmanremove=""
-	if stop; then
-		rm -f $LOCK_FILE
-	else
-		echo $errmsg
-		rtrn=1
-	fi
+	stop && rm -f $LOCK_FILE
 ;;
 restart|reload)
 	echo -n "Restarting cluster: "


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]