--- cman/init.d/cman.in.orig	2008-12-30 22:03:01.000000000 +0100
+++ cman/init.d/cman.in	2009-03-30 10:05:14.000000000 +0200
@@ -9,14 +9,26 @@
 ### BEGIN INIT INFO
 # Provides:		cman
 # Required-Start:	$network
-# Required-Stop:	$network
-# Default-Start:
+# Required-Stop:	gfs gfs2
+# Default-Start:	2 3 5
 # Default-Stop:
 # Short-Description:	Starts and stops cman
 # Description:		Starts and stops the Cluster Manager set of daemons
 ### END INIT INFO
 
-. /etc/init.d/functions
+. /etc/rc.status
+
+# Shell functions sourced from /etc/rc.status:
+#      rc_check         check and set local and overall rc status
+#      rc_status        check and set local and overall rc status
+#      rc_status -v     ditto but be verbose in local rc status
+#      rc_status -v -r  ditto and clear the local rc status
+#      rc_failed        set local and overall rc status to failed
+#      rc_reset         clear local rc status (overall remains)
+#      rc_exit          exit appropriate to overall rc status
+
+# First reset status of this service
+rc_reset
 
 [ -f /etc/sysconfig/cman ] && . /etc/sysconfig/cman
 [ -z "$CCSD_OPTS" ] && CCSD_OPTS=
@@ -82,10 +94,15 @@
 
 load_modules()
 {
-    errmsg=$( /sbin/modprobe configfs 2>&1 ) || return 1
-    errmsg=$( /sbin/modprobe dlm 2>&1 ) || return 1
-    errmsg=$( /sbin/modprobe lock_dlm 2>&1 ) || return 1
-    return 0
+    echo -n "    configfs "    
+    /sbin/modprobe configfs
+    rc_status -v
+    echo -n "    dlm "
+    /sbin/modprobe dlm
+    rc_status -v
+    echo -n "    lock_dlm "
+    /sbin/modprobe lock_dlm
+    rc_status -v
 }
 
 start_configfs()
@@ -95,41 +112,37 @@
     && 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 $?
+	/bin/mount -t configfs none /sys/kernel/config
+	rc_status
+    else
+	rc_failed
     fi
-    return 0
+    rc_status -v
 }
 
 start_ccsd()
 {
     # ccsd
-    status ccsd &> /dev/null
-    if [ $? -ne 0 ]
-    then
-	errmsg=$(/sbin/ccsd $CCSD_OPTS 2>&1)
-	rtrn=$?
-	return $rtrn
-    fi
-    return 0
+    startproc /usr/sbin/ccsd $CCSD_OPTS
+    rc_status -v
+    sleep 2
 }
 
 start_cman()
 {
     # cman
-    /sbin/cman_tool status &> /dev/null
+    /usr/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
-
+	/usr/sbin/cman_tool -t $CMAN_CLUSTER_TIMEOUT -w join $cman_join_opts
+	rc_status
 	if [ $CMAN_QUORUM_TIMEOUT -gt 0 ]
 	then
-	    errmsg=$( /sbin/cman_tool -t $CMAN_QUORUM_TIMEOUT \
-		    -q wait 2>&1 ) || return 1
+	    /usr/sbin/cman_tool -t $CMAN_QUORUM_TIMEOUT -q wait
+	    rc_status
 	fi
     fi
-    return 0
+    rc_status -v
 }
 
 
@@ -142,73 +155,74 @@
     # Start qdiskd before fenced to resolve bug #436381.  This only
     # happens if qdiskd is configured to run in the runlevel we are in
     #
-    /sbin/chkconfig --levels "$current_runlevel" qdiskd 2>/dev/null
+    /sbin/chkconfig -c qdiskd 2>/dev/null
     if [ $? -ne 0 ]; then
         # qdiskd doesn't start at this runlevel.
-        return 0
+        return 1
     fi
 
     echo -n "   Starting qdiskd... "
     /sbin/service qdiskd start &> /dev/null
-    if [ $? -eq 0 ] 
-    then
-	echo "done"
-    else
-	echo "failed"
-	return 1
-    fi
-    return 0
+    rc_status -v
 }
 
 
 start_daemons()
 {
-    status groupd &> /dev/null
+    checkproc /usr/sbin/groupd &> /dev/null
     if [ $? -ne 0 ]; then
-	errmsg=$( /sbin/groupd 2>&1 ) || return 1
+	echo -n "    groupd "
+	startproc /usr/sbin/groupd
+	rc_status -v
     fi
-    status fenced &> /dev/null
+    checkproc /usr/sbin/fenced &> /dev/null
     if [ $? -ne 0 ]; then
-	errmsg=$( /sbin/fenced 2>&1 ) || return 1
+	echo -n "    fenced "
+	startproc /usr/sbin/fenced
+	rc_status -v
     fi
-    status dlm_controld &> /dev/null
+    checkproc /usr/sbin/dlm_controld &> /dev/null
     if [ $? -ne 0 ]; then
-	errmsg=$( /sbin/dlm_controld 2>&1 ) || return 1
+	echo -n "    dlm_controld "
+	startproc /usr/sbin/dlm_controld
+	rc_status -v
     fi
-    status gfs_controld &> /dev/null
+    checkproc /usr/sbin/gfs_controld &> /dev/null
     if [ $? -ne 0 ]; then
-	errmsg=$( /sbin/gfs_controld 2>&1 ) || return 1
+	echo -n "    gfs_controld "
+	startproc /usr/sbin/gfs_controld
+	rc_status -v
     fi
-    return 0
+    rc_status
 }
 
 start_fence()
 {
-    /sbin/cman_tool status | grep Flags | grep 2node &> /dev/null
+    /usr/sbin/cman_tool status | grep Flags | grep 2node &> /dev/null
     if [ $? -ne 0 ]
     then
-        errmsg=$( /sbin/fence_tool -w -t $FENCED_START_TIMEOUT join \
-                 > /dev/null 2>&1 ) || return 1
+        /usr/sbin/fence_tool -w -t $FENCED_START_TIMEOUT join > /dev/null 2>&1
+	rc_status -v
     else
-        errmsg=$( /sbin/fence_tool -w -t $FENCED_START_TIMEOUT \
-                 -m $FENCED_MEMBER_DELAY join \
-                 > /dev/null 2>&1 ) || return 1
+        /usr/sbin/fence_tool -w -t $FENCED_START_TIMEOUT -m $FENCED_MEMBER_DELAY join > /dev/null 2>&1
+	rc_status -v
     fi
-    return 0
+    rc_status
 }
 
 start_fence_xvmd()
 {
-    status fence_xvmd &> /dev/null
+    checkproc /usr/sbin/fence_xvmd &> /dev/null
     if [ $? -ne 0 ]; then
-	errmsg=$( /sbin/fence_xvmd $FENCE_XVMD_OPTS 2>&1 ) || return 1
+	startproc /usr/sbin/fence_xvmd $FENCE_XVMD_OPTS
+	rc_status -v
     fi
-    return 0
+    rc_status
 }
 
 xend_bridged_net_enabled() {
 	# Not a xen kernel
-	test -d /proc/xen || return 1
+	test -d /proc/xen || rc_failed
 
     current_runlevel=$(/sbin/runlevel 2>/dev/null | awk '{ print $2 }' 2>/dev/null)
     if [ -z "$current_runlevel" ]; then
@@ -216,7 +230,7 @@
         return 1
     fi
 
-    /sbin/chkconfig --levels "$current_runlevel" xend 2>/dev/null
+    /sbin/chkconfig -c xend 2>/dev/null
     if [ $? -ne 0 ]; then
         # xend doesn't start at this runlevel.
         return 1
@@ -242,14 +256,14 @@
         else
             errmsg='The xend bridged network script is missing'
         fi
-        return 1
+        rc_failed
     fi
 
     /sbin/modprobe netbk >& /dev/null
     /sbin/modprobe netloop >& /dev/null
     bridge_parms=`egrep -m 1 "^[[:blank:]]*\([[:blank:]]*network-script[[:blank:]]+(')?[[:blank:]]*${NETWORK_BRIDGE_SCRIPT}([[:blank:]]*\)|[[:blank:]]+)" /etc/xen/xend-config.sxp| sed -r "s/^[[:blank:]]*\([[:blank:]]*network-script[[:blank:]]+'?[[:blank:]]*${NETWORK_BRIDGE_SCRIPT}[[:blank:]]*//; s/'?[[:blank:]]*\).*//"`
-    errmsg=$(/etc/xen/scripts/${NETWORK_BRIDGE_SCRIPT} start $bridge_parms 2>&1) || return 1
-    return 0
+    errmsg=$(/etc/xen/scripts/${NETWORK_BRIDGE_SCRIPT} start $bridge_parms 2>&1) || rc_failed
+    rc_status
 }
 
 fence_xvmd_enabled()
@@ -285,7 +299,7 @@
 {
     if [ ! -f  /proc/sys/net/core/rmem_default ]
     then
-	return 0;
+	rc_status
     fi
    
     value="$(cat /proc/sys/net/core/rmem_default)"
@@ -299,6 +313,7 @@
         then
         echo $NET_RMEM_MAX > /proc/sys/net/core/rmem_max
     fi
+    rc_status -v
 }
 
 fence_join_enabled()
@@ -325,100 +340,37 @@
     then
         echo -n "   Enabling workaround for Xend bridged networking... "
         xend_bridged_net_start
-        if [ $? -eq 0 ] 
-        then
-            echo "done"
-        else
-            echo "failed: $errmsg"
-			return 1
-        fi
     fi
 
-    echo -n "   Loading modules... "
+    echo "   Loading modules... "
     ulimit -c unlimited
     load_modules
-    if [ $? -eq 0 ] 
-    then
-	echo "done"
-    else
-	echo "failed"
-	return 1
-    fi
 
     echo -n "   Mounting configfs... "
     start_configfs
-    if [ $? -eq 0 ] 
-    then
-	echo "done"
-    else
-	echo "failed"
-	return 1
-    fi
 
     echo -n "   Setting network parameters... "
     set_networking_params
-    if [ $? -eq 0 ] 
-    then
-	echo "done"
-    else
-	echo "failed"
-	return 1
-    fi
 
     echo -n "   Starting ccsd... "
     start_ccsd
-    if [ $? -eq 0 ] 
-    then
-	echo "done"
-    else
-	echo "failed"
-	return 1
-    fi
 
     echo -n "   Starting cman... "
     start_cman
-    if [ $? -eq 0 ] 
-    then
-	echo "done"
-    else
-	echo "failed"
-	return 1
-    fi
 
     start_qdiskd
 
-    echo -n "   Starting daemons... "
+    echo "   Starting daemons... "
     start_daemons
-    if [ $? -eq 0 ] 
-    then
-	echo "done"
-    else
-	echo "failed"
-	return 1
-    fi
 
     if fence_join_enabled; then
 	echo -n "   Starting fencing... "
 	start_fence
-	if [ $? -eq 0 ] 
-	    then
-	    echo "done"
-	else
-	    echo "failed"
-	    return 1
-	fi
     fi
 
     if fence_xvmd_enabled; then
 	echo -n "   Starting virtual machine fencing host... "
 	start_fence_xvmd
-	if [ $? -eq 0 ]
-	then
-	    echo "done"
-	else
-	    echo "failed"
-	return 1
-	fi
     fi
     
     return 0
@@ -430,13 +382,12 @@
     && awk '{ print $3 }' /etc/mtab | grep "configfs" &> /dev/null
     if [ $? -eq 0 ] && [ -z "$(ls -1 /sys/kernel/config)" ]
     then
-	errmsg=$( /bin/umount /sys/kernel/config 2>&1 )
-	if [ $? -ne 0 ]
-	then
-	    echo -n $errmsg " "
-	fi
+	/bin/umount /sys/kernel/config
+	rc_status
+    else
+	rc_failed
     fi
-    return 0
+    rc_status -v
 }
 
 stop_ccsd()
@@ -450,23 +401,23 @@
 	    [ -r /var/run/cluster/ccsd.pid ] || break
 
 	    pid=$(cat /var/run/cluster/ccsd.pid)
-	    /usr/bin/kill $pid &> /dev/null || break
-	    
+	    /bin/kill $pid &> /dev/null || break
+	    rc_status
 	    sleep 1
 	else
-	    return 0
+	    rc_status
 	fi
     done
-    return 1
+    rc_status -v
 }
 
 stop_cman()
 {
-    /sbin/cman_tool status &> /dev/null
+    /usr/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
+    /usr/sbin/cman_tool -t $CMAN_SHUTDOWN_TIMEOUT -w leave $1
+    rc_status -v
     fi
     return 0 # all ok
 }
@@ -474,17 +425,18 @@
 stop_daemons()
 {
     if pid=$(/sbin/pidof gfs_controld 2>&1); then
-	errmsg=$(/usr/bin/kill $pid 2>&1) || return 1
+	errmsg=$(/bin/kill $pid 2>&1) || return 1
     fi
     if pid=$(/sbin/pidof dlm_controld 2>&1); then
-	errmsg=$(/usr/bin/kill $pid 2>&1) || return 1
+	errmsg=$(/bin/kill $pid 2>&1) || return 1
     fi
     if pid=$(/sbin/pidof fenced 2>&1); then
-	errmsg=$(/usr/bin/kill $pid 2>&1) || return 1
+	errmsg=$(/bin/kill $pid 2>&1) || return 1
     fi
     if pid=$(/sbin/pidof groupd 2>&1); then
-	errmsg=$(/usr/bin/kill $pid 2>&1) || return 1
+	errmsg=$(/bin/kill $pid 2>&1) || return 1
     fi
+    rc_status
     return 0 # all ok
 }
 
@@ -492,11 +444,11 @@
 {
     if /sbin/pidof fenced &> /dev/null
     then
-	/sbin/fence_tool -w leave > /dev/null 2>&1
-	rtrn=$?
+	/usr/sbin/fence_tool -w leave
+	rc_status -v
 	sleep 1 # A bit of time for fenced to exit
-	return $rtrn
     fi
+    rc_status
     return 0 # all ok
 }
 
@@ -504,7 +456,8 @@
 {
     if /sbin/pidof fence_xvmd &> /dev/null
     then
-    	pkill -TERM fence_xvmd
+    	kill -TERM fence_xvmd
+	rc_status -v
 	sleep 1 # A bit of time for fenced to exit
     fi
     
@@ -519,25 +472,11 @@
     if fence_xvmd_enabled; then
 	echo -n "   Stopping virtual machine fencing host... "
 	stop_fence_xvmd
-	if [ $? -eq 0 ]
-	then
-	    echo "done"
-	else
-	    echo "failed"
-	    return 1
-	fi
     fi
 
     if fence_join_enabled; then
 	echo -n "   Stopping fencing... "
 	stop_fence
-	if [ $? -eq 0 ]
-	    then
-	    echo "done"
-	else
-	    echo "failed"
-	    return 1
-	fi
     fi
 
     echo -n "   Stopping cman... "
@@ -546,52 +485,42 @@
     else
 	stop_cman
     fi
-    if [ $? -eq 0 ]
-    then
-	echo "done"
-    else
-	echo "failed"
-	return 1
-    fi
 
 #   stop_daemons
 #   [ $? -ne 0 ] && return 1
 
     echo -n "   Stopping ccsd... "
     stop_ccsd
-    if [ $? -eq 0 ]
-    then
-	echo "done"
-    else
-	echo "failed"
-	return 1
-    fi
 
     echo -n "   Unmounting configfs... "
     stop_configfs
-    if [ $? -eq 0 ]
-    then
-	echo "done"
-    else
-	echo "failed"
-	return 1
-    fi
 
     return 0
 }
 
 cmanstatus()
 {
-	errmsg=$( status ccsd 2>&1) || return 1
-	errmsg=$( status groupd 2>&1) || return 1
-	errmsg=$( status fenced 2>&1) || return 1
-	errmsg=$( status dlm_controld 2>&1) || return 1
-	errmsg=$( status gfs_controld 2>&1) || return 1
-	
-	fence_xvmd_enabled || return 0
-	errmsg=$( status fence_xvmd 2>&1) || return 1
-
-	return 0
+        echo -n "Checking ccsd "
+        checkproc /usr/sbin/ccsd
+        rc_status -v
+        echo -n "Checking groupd "
+        checkproc /usr/sbin/groupd
+        rc_status -v
+        echo -n "Checking fenced "
+        checkproc /usr/sbin/fenced
+        rc_status -v
+        echo -n "Checking dlm_controld "
+        checkproc /usr/sbin/dlm_controld
+        rc_status -v
+        echo -n "Checking gfs_controld "
+        checkproc /usr/sbin/gfs_controld
+        rc_status -v
+
+        fence_xvmd_enabled || return 0
+        echo "Checking fence_xvmd "
+        checkproc /usr/sbin/fence_xvmd
+        rc_status -v
+        return 0
 }
 
 rtrn=1
@@ -600,17 +529,6 @@
 case "$1" in
     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)
 	if [ $2 ]; then
@@ -618,17 +536,6 @@
 	else
 	    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|reload)
@@ -639,12 +546,6 @@
 
     status)
 	cmanstatus
-	rtrn=$?
-	if [ $rtrn -ne 0 ] ; then
-	    echo $errmsg
-	else
-	    echo "cman is running."
-	fi
 	;;
 
     *)
@@ -652,4 +553,4 @@
 	    ;;
 esac
 
-exit $rtrn
+rc_exit
