All of lore.kernel.org
 help / color / mirror / Atom feed
From: rmccabe@sourceware.org <rmccabe@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] conga/ricci/init.d ricci
Date: 19 Feb 2008 22:49:31 -0000	[thread overview]
Message-ID: <20080219224931.12883.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe at sourceware.org	2008-02-19 22:49:31

Modified files:
	ricci/init.d   : ricci 

Log message:
	clean up init script
	get rid of unconditional 8s sleep

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/init.d/ricci.diff?cvsroot=cluster&r1=1.13&r2=1.14

--- conga/ricci/init.d/ricci	2008/01/02 20:47:34	1.13
+++ conga/ricci/init.d/ricci	2008/02/19 22:49:30	1.14
@@ -7,7 +7,7 @@
 #
 # description:  Starts and stops Red Hat Cluster and Storage Remote \
 #               Configuration Interface (ricci)
-# chkconfig: 2345 99 01
+# chkconfig: - 99 01
 #
 
 # Source function library
@@ -53,16 +53,67 @@
 {
 	rm -f "$SSL_PUBKEY" "$SSL_PRIVKEY"
 	echo -n "generating SSL certificates...  "
-	/usr/bin/openssl genrsa -out "$SSL_PRIVKEY" 2048 >&/dev/null
-	/usr/bin/openssl req -new -x509 -key "$SSL_PRIVKEY" -out "$SSL_PUBKEY" -days 1825 -config /var/lib/ricci/certs/cacert.config
-	/bin/chown $RUNASUSER:$RUNASUSER "$SSL_PRIVKEY" "$SSL_PUBKEY"
+	/usr/bin/openssl genrsa -out "$SSL_PRIVKEY" 2048 >&/dev/null &&
+	/usr/bin/openssl req -new -x509 -key "$SSL_PRIVKEY" -out "$SSL_PUBKEY" -days 1825 -config /var/lib/ricci/certs/cacert.config &&
+	/bin/chown $RUNASUSER:$RUNASUSER "$SSL_PRIVKEY" "$SSL_PUBKEY" &&
+	/bin/chmod 600 "$SSL_PRIVKEY" &&
 	/bin/chmod 644 "$SSL_PUBKEY"
-	/bin/chmod 600 "$SSL_PRIVKEY"
 	ret=$?
 	echo "done"
 	return $ret
 }
 
+check_ricci_lockfiles() {
+	ricci_status >& /dev/null
+	ret=$?
+	if [ "$ret" -eq 1 ] || [ "$ret" -eq 2 ]; then
+		# stale pid and/or lockfile
+		rm -f -- "$PIDFILE" "$LOCKFILE"
+	fi
+}
+
+ricci_status() {
+	status -p "$PIDFILE" "$RICCID"
+	ricci_up=$?
+	return $ricci_up
+}
+
+ricci_stop() {
+	ricci_status >& /dev/null
+	ret=$?
+
+	if [ "$ret" -ne 0 ]; then
+		# already stopped - no error
+		check_ricci_lockfiles
+		return 0
+	fi
+
+	killproc "$RICCID" SIGTERM
+
+	ricci_status >& /dev/null
+	ret=$?
+
+	max_wait=10
+	cur_wait=0
+	while [ $ret -eq 0 ] && [ $cur_wait -lt $max_wait ]; do
+		sleep 1
+		cur_wait=`expr $cur_wait + 1`
+        ricci_status >& /dev/null
+		ret=$?
+    done
+
+	ricci_status >& /dev/null
+	ret=$?
+
+	if [ "$ret" -ne 0 ]; then
+		rm -f -- "$PIDFILE" "$LOCKFILE"
+		/usr/bin/logger -t "$RICCID" -- "shutdown succeeded"
+		return 0
+	fi
+
+	/usr/bin/logger -t "$RICCID" -- "shutdown failed"
+	return 1
+}
 
 case $1 in
 	start)
@@ -71,39 +122,40 @@
 			service messagebus start
 			service messagebus status >&/dev/null
 			if [ $? -ne 0 ]; then
-				echo "not starting ricci..."
-				/usr/bin/logger -t $RICCID "startup failed"
+				/usr/bin/logger -t "$RICCID" -- "messagebus startup failed"
+				failure "not starting $RICCID"
 				exit 1
 			fi
 		fi
+
 		service oddjobd status >&/dev/null
 		if [ $? -ne 0 ]; then
 			service oddjobd start
 			service oddjobd status >&/dev/null
 			if [ $? -ne 0 ]; then
-				echo "not starting ricci..."
-				/usr/bin/logger -t $RICCID "startup failed"
+				/usr/bin/logger -t "$RICCID" -- "oddjob startup failed"
+				failure "not starting $RICCID"
 				exit 1
 			fi
 		fi
 
 		service saslauthd start >&/dev/null
 		ssl_certs_ok
-		if [ "1$?" != "10" ] ; then
+		if [ $? -ne 0 ] ; then
 			generate_ssl_certs
 		fi
-
-		NewUID=`grep "^$RUNASUSER:" /etc/passwd | sed -e 's/^[^:]*:[^:]*://' -e 's/:.*//'`
+		check_ricci_lockfiles
+		NewUID=`grep "^$RUNASUSER:" /etc/passwd | cut -d: -f3`
 		echo -n $"Starting $ID: "
-		daemon $RICCID -u $NewUID
-		rtrn=$?
+		daemon "$RICCID" -u "$NewUID"
 		echo
+		rtrn=$?
 
 		if [ $rtrn -eq 0 ]; then
-			touch "$LOCKFILE"
-			/usr/bin/logger -t $RICCID "startup succeeded"
+			touch -- "$LOCKFILE"
+			/usr/bin/logger -t $RICCID -- "startup succeeded"
 		else
-			/usr/bin/logger -t $RICCID "startup failed"
+			/usr/bin/logger -t $RICCID -- "startup failed"
 		fi
 	;;
 
@@ -114,24 +166,13 @@
 	;;
 
 	status)
-		status $RICCID
+		ricci_status
 		rtrn=$?
 	;;
 
 	stop)
 		echo -n "Shutting down $ID: "
-		killproc $RICCID SIGTERM
-		rtrn=$?
-		if [ $rtrn -eq 0 ]; then
-			sleep 8
-			rm -f $PIDFILE
-			rm -f $LOCKFILE
-			/usr/bin/logger -t $RICCID "shutdown succeeded"
-			rtrn=0
-		else
-			/usr/bin/logger -t $RICCID "shutdown failed"
-			rtrn=1
-		fi
+		ricci_stop
 		echo
 	;;
 
@@ -142,6 +183,10 @@
 		fi
 	;;
 
+	try-restart)
+		rtrn=3
+	;;
+
 	reload)
 		rtrn=3
 	;;



             reply	other threads:[~2008-02-19 22:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-19 22:49 rmccabe [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-06-05 16:22 [Cluster-devel] conga/ricci/init.d ricci rmccabe

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=20080219224931.12883.qmail@sourceware.org \
    --to=rmccabe@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.