[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] cluster/cman/init.d cman



CVSROOT:	/cvs/cluster
Module name:	cluster
Changes by:	adas sourceware org	2006-06-28 20:57:03

Modified files:
	cman/init.d    : cman 

Log message:
	Single init script to start up cluster: Covers loading of modules, starting ccsd, cman and fencing, and starting daemons. Replaces ccsd, cman and fenced init scripts

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/init.d/cman.diff?cvsroot=cluster&r1=1.15&r2=1.16

--- cluster/cman/init.d/cman	2006/05/08 22:38:29	1.15
+++ cluster/cman/init.d/cman	2006/06/28 20:57:03	1.16
@@ -3,11 +3,12 @@
 # chkconfig: 345 21 79
 # description: Starts and stops cman
 #
-#	       
+#
 ### BEGIN INIT INFO
-# Provides: 
+# Provides:
 ### END INIT INFO
-
+. /etc/init.d/functions
+CCSD_OPTS=-X
 # CMAN_CLUSTER_TIMEOUT -- amount of time to wait for joinging a cluster
 #     before giving up.  If CMAN_CLUSTER_TIMEOUT is positive, then we will
 #     wait CMAN_CLUSTER_TIMEOUT seconds before giving up and failing when
@@ -20,166 +21,265 @@
 #     startup quorum is needed by many other applications, so we may as 
 #     well wait here.  If CMAN_QUORUM_TIMEOUT is less than 1, quorum will 
 #     be ignored.
-CMAN_QUORUM_TIMEOUT=300
+#CMAN_QUORUM_TIMEOUT=300
+CMAN_QUORUM_TIMEOUT=0
 
 # CMAN_SHUTDOWN_TIMEOUT -- amount of time to wait for cman to become a 
 #     cluster member before calling cman_tool leave during shutdown.  
 #     default is 60 seconds
 CMAN_SHUTDOWN_TIMEOUT=60
 
-. /etc/init.d/functions
-[ -f /etc/sysconfig/cluster ] && . /etc/sysconfig/cluster
+# FENCED_START_TIMEOUT -- amount of time to wait for starting fenced
+#     before giving up.  If FENCED_START_TIMEOUT is positive, then we will
+#     wait FENCED_START_TIMEOUT seconds before giving up and failing when
+#     fenced does not start.  If FENCED_START_TIMEOUT is zero, then
+#     wait indefinately for fenced to start.
+FENCED_START_TIMEOUT=120
 
 LOCK_FILE="/var/lock/subsys/cman"
 
 [ -n "$CLUSTERNAME" ] && cman_join_opts="-c $CLUSTERNAME"
 
-in_cluster()
+load_modules()
 {
-	grep -q "Cluster Member: Yes" /proc/cluster/status
+    errmsg=$( /sbin/modprobe configfs 2>&1 ) || return 1
+    errmsg=$( /sbin/modprobe dlm 2>&1 ) || return 1
+    errmsg=$( /sbin/modprobe dlm_device 2>&1 ) || return 1
+    return 0
 }
 
-start()
+start_configfs()
+{
+    # configfs
+    awk '{ print $2 }' /etc/mtab | grep "/sys/kernel/config" &> /dev/null \
+    && awk '{ print $3 }' /etc/mtab | grep "configfs" &> /dev/null
+    if [ $? -ne 0 ]
+    then
+	errmsg=$( /bin/mount -t configfs none /sys/kernel/config 2>&1 )
+	return $?
+    fi
+    return 0
+}
+
+start_ccsd()
+{
+    # ccsd
+    status ccsd &> /dev/null
+    if [ $? -ne 0 ]
+    then
+	errmsg=$(/sbin/ccsd $CCSD_OPTS 2>&1)
+	return $?
+    fi
+    return 0
+}
+
+start_cman()
 {
-	echo -n "Starting cman:"
+    # cman
+    /sbin/cman_tool status &> /dev/null
+    if [ $? -ne 0 ]
+    then
+	errmsg=$( /sbin/cman_tool -t $CMAN_CLUSTER_TIMEOUT -w join \
+	    $cman_join_opts 2>&1 ) || return 1
 
-	# If gulm is in ccs, don't start cman
-	# FIXME -- Should this be silent?  I think users should get some
-	#          feedback, but others might not want added verbosity to
-	#          the boot process.  Oh well... it's only one line :)
-	if ! [ -r /etc/cluster/cluster.conf ]
-	then
-		# TODO -- cman can start w/out cluster.conf file.  This 
-		#	  should not stop cman from starting up.
-		initlog -n ${0##*/} -s "/etc/cluster/cluster.conf was not detected"
-	elif grep -qE "<[[:space:]]*gulm([[:space:]]|[>]|$)" \
-		/etc/cluster/cluster.conf 
+	if [ $CMAN_QUORUM_TIMEOUT -gt 0 ]
 	then
-		warning "Skipping because of <gulm> section detected in " \
-			"/etc/cluster/cluster.conf"
-		echo
-		exit 0
+	    errmsg=$( /sbin/cman_tool -t $CMAN_QUORUM_TIMEOUT \
+		    -q wait 2>&1 ) || return 1
 	fi
+    fi
+    return 0
+}
 
-	rtrn=1
+start_daemons()
+{
+    status groupd &> /dev/null
+    if [ $? -ne 0 ]; then
+	errmsg=$( /sbin/groupd 2>&1 ) || return 1
+    fi
+    status fenced &> /dev/null
+    if [ $? -ne 0 ]; then
+	errmsg=$( /sbin/fenced 2>&1 ) || return 1
+    fi
+    status dlm_controld &> /dev/null
+    if [ $? -ne 0 ]; then
+	errmsg=$( /sbin/dlm_controld 2>&1 ) || return 1
+    fi
+    status gfs_controld &> /dev/null
+    if [ $? -ne 0 ]; then
+	errmsg=$( /sbin/gfs_controld 2>&1 ) || return 1
+    fi
+    return 0
+}
 
-	for try in block
-	do
-		# load the cman module (modprobe won't error if the modules 
-		# are already loaded
-		errmsg=$(modprobe cman 2>&1) || break
-
-		# try to load the dlm module
-		modprobe dlm &> /dev/null
-
-		# TODO -- configure tunable paramters?
-		# [ -n "$CMAN_TRANSITION_RESTARTS" ] && 
-		#	echo $CMAN_TRANSITION_RESTARTS > \
-		#	/proc/cluster/config/cman/transition_restarts
-
-		if in_cluster
-		then
-			rtrn=0
-			break
-		fi
-
-		# specify -w to make sure we have joined the cluster
-		# TODO -- should we call cman_tool leave if this times out?
-		errmsg=$(cman_tool -t $CMAN_CLUSTER_TIMEOUT -w join \
-			$cman_join_opts 2>&1) || break
-
-		# make sure that we are quorate?  
-		if [ $CMAN_QUORUM_TIMEOUT -gt 0 ]
-		then
-			errmsg=$( cman_tool -t $CMAN_QUORUM_TIMEOUT \
-				-q wait 2>&1 ) || break
-		fi
+start_fence()
+{
+    errmsg=$( /sbin/fence_tool -j $FENCED_START_TIMEOUT join \
+	     > /dev/null 2>&1 ) || return 1
+    return 0
+}
 
-		rtrn=0
-	done
+start()
+{
+    echo -n "Starting cluster: "
+    load_modules
+    [ $? -ne 0 ] && return 1
+    start_configfs
+    [ $? -ne 0 ] && return 1
+    start_ccsd
+    [ $? -ne 0 ] && return 1
+    start_cman
+    [ $? -ne 0 ] && return 1
+    start_daemons
+    [ $? -ne 0 ] && return 1
+    start_fence
+    [ $? -ne 0 ] && return 1
+    
+    return 0
+}
+
+stop_configfs()
+{
+    awk '{ print $2 }' /etc/mtab | grep "/sys/kernel/config" &> /dev/null\
+    && awk '{ print $3 }' /etc/mtab | grep "configfs" &> /dev/null
+    if [ $? -eq 0 ]
+    then
+	errmsg=$( /bin/umount /sys/kernel/config 2>&1 )
+	return $?
+    fi
+    return 0
+}
 
-	if [ $rtrn -eq 0 ]
+stop_ccsd()
+{
+    for sec in $(seq 1 10)
+    do
+	if /sbin/pidof ccsd &> /dev/null
 	then
-		success "startup"
-		echo
+	    # get the pid of ccsd from /var/run/cluster/ccsd.pid
+	    # and break if the file is not there
+	    [ -r /var/run/cluster/ccsd.pid ] || break
+
+	    pid=$(cat /var/run/cluster/ccsd.pid)
+	    /usr/bin/kill $pid &> /dev/null || break
+	    
+	    sleep 1
 	else
-		failure "$errmsg"
-		echo
+	    return 0
 	fi
-		
-	# need the extra echo to properlly terminate the line
-	return $rtrn
+    done
+    return 1
 }
 
-# This function can be called with an additional argument, remove
-# The cman_tool command will fail if the additional argument is
-# something else.
-stop()
+stop_cman()
 {
-	echo -n "Stopping cman:"
-	rtrn=0
-	if [ -r /proc/cluster/status ]
-	then
-		rtrn=1
+    /sbin/cman_tool status &> /dev/null
+    if [ $? -eq 0 ]
+    then
+    errmsg=$( /sbin/cman_tool -t $CMAN_SHUTDOWN_TIMEOUT \
+	    -w leave $1 2>&1 ) || return 1
+    fi
+    return 0 # all ok
+}
 
-		cman_tool -t $CMAN_SHUTDOWN_TIMEOUT -w leave $1 &> /dev/null && rtrn=0
+stop_daemons()
+{
+    if pid=$(/sbin/pidof gfs_controld 2>&1); then
+	errmsg=$(/usr/bin/kill -9 $pid 2>&1) || return 1
+    fi
+    if pid=$(/sbin/pidof dlm_controld 2>&1); then
+	errmsg=$(/usr/bin/kill -9 $pid 2>&1) || return 1
+    fi
+    if pid=$(/sbin/pidof fenced 2>&1); then
+	errmsg=$(/usr/bin/kill -9 $pid 2>&1) || return 1
+    fi
+    if pid=$(/sbin/pidof groupd 2>&1); then
+	errmsg=$(/usr/bin/kill -9 $pid 2>&1) || return 1
+    fi
+    return 0 # all ok
+}
 
-		# allow cman time to clean up BZ 149282
-		sleep 3
+stop_fence()
+{
+    if /sbin/pidof fenced &> /dev/null
+    then
+	/sbin/fence_tool leave > /dev/null 2>&1
+	return $?
+    fi
+    return 0 # all ok
+}
 
-		# try to unload dlm module
-		modprobe -r dlm &>/dev/null
- 
-		modprobe -r cman &>/dev/null
-	fi
-	
-	if [ $rtrn -eq 0 ]
-	then
-		success "shutdown"
-		echo
-	else
-		failure "failed to stop cman"
-		echo
-	fi
-		
-	# need the extra echo to properlly terminate the line
-	return $rtrn
+stop()
+{
+    echo -n "Stopping cluster: "
+    stop_fence
+    [ $? -ne 0 ] && return 1
+    stop_daemons
+    [ $? -ne 0 ] && return 1
+    if [ $1 ]; then
+	stop_cman $1
+    else
+	stop_cman
+    fi
+    [ $? -ne 0 ] && return 1
+    stop_ccsd
+    [ $? -ne 0 ] && return 1
+    stop_configfs
+    [ $? -ne 0 ] && return 1
+    return 0
 }
 
 rtrn=1
 
 # See how we were called.
 case "$1" in
-  start)
+    start)
 	start
 	rtrn=$?
 	[ $rtrn = 0 ] && touch $LOCK_FILE
+	if [ $rtrn -ne 0 ] 
+	then
+	    echo $errmsg
+	    failure "failed to start cman"
+	    echo
+	else
+	    success "start"
+	    echo
+	fi
 	;;
-
-  stop)
+    stop)
 	if [ $2 ]; then
-		stop
+	    stop
 	else
-		stop remove
+	    stop remove
 	fi
 	rtrn=$?
 	[ $rtrn = 0 ] && rm -f $LOCK_FILE
+	if [ $rtrn -ne 0 ] 
+	then
+	    echo $errmsg
+	    failure "failed to stop cman"
+	    echo
+	else
+	    success "shutdown"
+	    echo
+	fi
 	;;
 
-  restart)
+    restart)
 	$0 stop restart
-	$0 start 
+	$0 start
 	rtrn=$?
 	;;
 
-  status)
-	cat /proc/cluster/status 2>/dev/null
+    status)
+	/sbin/cman_tool status 2>/dev/null
 	rtrn=$?
 	;;
 
-  *)
-	echo $"Usage: $0 {start|stop|restart|status}"
-	;;
+    *)
+	    echo $"Usage: $0 {start|stop|restart|status}"
+	    ;;
 esac
 
 exit $rtrn


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]