cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: adas@sourceware.org <adas@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] cluster/cman/init.d cman
Date: 28 Jun 2006 20:57:03 -0000	[thread overview]
Message-ID: <20060628205703.19110.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/cluster
Module name:	cluster
Changes by:	adas at 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



             reply	other threads:[~2006-06-28 20:57 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-28 20:57 adas [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-07-20 20:19 [Cluster-devel] cluster/cman/init.d cman rpeterso
2006-07-21 21:02 rpeterso
2006-08-25 22:04 adas
2006-08-31 18:00 rohara
2006-10-04 20:32 rpeterso
2006-10-18 21:48 rpeterso
2006-10-30 13:20 pcaulfield
2006-11-15 16:54 lhh
2006-11-15 16:55 lhh
2006-11-15 16:55 lhh
2006-12-08 22:01 adas
2006-12-08 22:01 adas
2007-04-27 15:07 rmccabe
2007-04-27 22:08 cfeist
2007-05-10 14:36 rmccabe
2007-05-10 14:45 rmccabe
2007-05-10 21:45 rmccabe
2007-07-12 19:50 rmccabe
2007-07-17 16:10 rmccabe
2007-12-11 11:22 pcaulfield
2007-12-11 14:04 pcaulfield
2008-01-18 16:47 adas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060628205703.19110.qmail@sourceware.org \
    --to=adas@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).