[PATCH 1/2] init: use checkpid when stopping the services

Federico Simoncelli fsimonce at redhat.com
Mon Aug 6 16:28:52 UTC 2012


When the pid file wasn't removed (eg: forced reboot, etc...) the
services were printing confusing warnings during restart/condrestart.

Signed-off-by: Federico Simoncelli <fsimonce at redhat.com>
---
 init.d/sanlock |   15 ++++++++-------
 init.d/wdmd    |   49 ++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 44 insertions(+), 20 deletions(-)

diff --git a/init.d/sanlock b/init.d/sanlock
index bd8dccb..83b35e8 100644
--- a/init.d/sanlock
+++ b/init.d/sanlock
@@ -48,7 +48,9 @@ start() {
 }
 
 stop() {
-	echo -n $"Sending stop signal $prog: "
+	PID=$(pidofproc -p $runfile $prog)
+
+	echo -n $"Sending stop signal $prog ($PID): "
 	killproc -p $runfile $prog -TERM
 	retval=$?
 	echo
@@ -57,9 +59,10 @@ stop() {
 		return $retval
 	fi
 
-	echo -n $"Waiting for $prog to stop:"
+	echo -n $"Waiting for $prog ($PID) to stop:"
+
 	timeout=10
-	while [ -e $runfile ]; do
+	while checkpid $PID; do
 		sleep 1
 		timeout=$((timeout - 1))
 		if [ "$timeout" -le 0 ]; then
@@ -74,9 +77,8 @@ stop() {
 }
 
 restart() {
-	stop && start
-	retval=$?
-	return $retval
+	rh_status_q && stop
+	start
 }
 
 reload() {
@@ -122,4 +124,3 @@ case "$1" in
 		exit 2
 esac
 exit $?
-
diff --git a/init.d/wdmd b/init.d/wdmd
index 19fc3ae..af45561 100644
--- a/init.d/wdmd
+++ b/init.d/wdmd
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 #
 # wdmd - watchdog multiplexing daemon
 #
@@ -31,20 +31,24 @@ WDMDOPTS="-G $WDMDGROUP"
 
 [ -f /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
 
-start() {
-	[ -x $exec ] || exit 5
-
-	if [ ! -d /var/run/$prog ]; then
-		mkdir -p /var/run/$prog
-		[ -x /sbin/restorecon ] && restorecon /var/run/$prog
-	fi
-
+watchdog_check() {
 	if [ ! -c /dev/watchdog ]; then
 		echo -n $"Loading the softdog kernel module: "
 		modprobe softdog && udevadm settle
 		[ -c /dev/watchdog ] && success || failure
 		echo
 	fi
+}
+
+start() {
+	watchdog_check
+
+	[ -x $exec ] || exit 5
+
+	if [ ! -d /var/run/$prog ]; then
+		install -d -g $WDMDGROUP -m 775 /var/run/$prog
+		[ -x /sbin/restorecon ] && restorecon /var/run/$prog
+	fi
 
 	echo -n $"Starting $prog: "
 	daemon $prog $WDMDOPTS
@@ -55,16 +59,36 @@ start() {
 }
 
 stop() {
-	echo -n $"Stopping $prog: "
+	PID=$(pidofproc -p $runfile $prog)
+
+	echo -n $"Sending stop signal $prog ($PID): "
 	killproc -p $runfile $prog -TERM
 	retval=$?
 	echo
-	[ $retval -eq 0 ] && rm -f $lockfile
+
+	if [ $retval -ne 0 ]; then
+		return $retval
+	fi
+
+	echo -n $"Waiting for $prog ($PID) to stop:"
+
+	timeout=10
+	while checkpid $PID; do
+		sleep 1
+		timeout=$((timeout - 1))
+		if [ "$timeout" -le 0 ]; then
+			failure; echo
+			return 1
+		fi
+	done
+
+	success; echo
+	rm -f $lockfile
 	return $retval
 }
 
 restart() {
-	stop
+	rh_status_q && stop
 	start
 }
 
@@ -111,4 +135,3 @@ case "$1" in
 		exit 2
 esac
 exit $?
-
-- 
1.7.1



More information about the sanlock-devel mailing list