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

[Cluster-devel] conga/ricci/init.d ricci



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe 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
 	;;


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