Skip to contentSkip to conversation

add try-restart init script action

PATCH In review Leonardo Chiquitto 1 participant 2 messages Jan 4, 2010 Kernel automounter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add try-restart init script action

autofs-5.0.5 - add try-restart init script action

Implement try-restart init script action to restart the service only if the service is already running. This action is part of LSB since version 1.9.

While there, fix some typos and adjust coding style for consistency.

redhat/autofs.init.in +10 -12
Index: autofs/redhat/autofs.init.in
===================================================================
@@ -26,7 +26,7 @@ DEVICE="autofs"
 initdir=@@initdir@@
 confdir=@@autofsconfdir@@
 
-test -e $DAEMON || exit 0
+test -x $DAEMON || exit 1
 
 if [ -r $initdir/functions ]; then
 	. $initdir/functions
@@ -36,7 +36,7 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin
 export PATH
 
 #
-# load customized configuation settings
+# load customized configuration settings
 #
 if [ -r $confdir/autofs ]; then
 	. $confdir/autofs
@@ -44,14 +44,12 @@ fi
 
 function start() {
 	# Make sure autofs4 module is loaded
-	if ! grep -q autofs /proc/filesystems
-	then
+	if ! grep -q autofs /proc/filesystems; then
 		echo -n "Loading $MODULE: "
-		# Try load the autofs4 module fail if we can't
-		modprobe $MODULE >/dev/null 2>&1
+		# Try to load the autofs4 module and fail if we can't
+		modprobe -q $MODULE >/dev/null 2>&1
 		RETVAL=$?
-		if [ $RETVAL -eq 1 ]
-		then
+		if [ $RETVAL -eq 1 ]; then
 			failure "Load $MODULE"
 			echo
 			return $RETVAL
@@ -59,8 +57,7 @@ function start() {
 			success "Load $MODULE"
 			echo
 		fi
-	elif ([ -f /proc/modules ] && lsmod) | grep -q autofs[^4]
-	then
+	elif ([ -f /proc/modules ] && lsmod) | grep -q autofs[^4]; then
 		RETVAL=1
 		failure "Load $MODULE"
 		echo
@@ -129,7 +126,7 @@ function reload() {
 		return $RETVAL
 	fi
 	pid=`pidof $prog`
-	if [ -z $pid ]; then
+	if [ -z "$pid" ]; then
 		echo $"$prog not running"
 		RETVAL=1
 	else
@@ -167,12 +164,13 @@ case "$1" in
 		reload
 		;;
 	condrestart)
+	try-restart)
 		if [ -f /var/lock/subsys/autofs ]; then
 			restart
 		fi
 		;;
 	*)
-		echo $"Usage: $0 {start|forcestart|stop|status|restart|forcerestart|reload|condrestart}"
+		echo $"Usage: $0 {start|forcestart|stop|status|restart|forcerestart|reload|condrestart|try-restart}"
 		exit 1;
 		;;
 esac
samples/rc.autofs.in +17 -15
Index: autofs/samples/rc.autofs.in
===================================================================
@@ -24,13 +24,13 @@ MODULE="autofs4"
 DEVICE="autofs"
 confdir=@@autofsconfdir@@
 
-test -e $DAEMON || exit 0
+test -x $DAEMON || exit 1
 
 PATH=/sbin:/usr/sbin:/bin:/usr/bin
 export PATH
 
 #
-# load customized configuation settings
+# load customized configuration settings
 #
 if [ -r $confdir/autofs ]; then
 	. $confdir/autofs
@@ -40,20 +40,17 @@ function start() {
 	echo -n "Starting $prog: "
 
 	# Make sure autofs4 module is loaded
-	if ! grep -q autofs /proc/filesystems
-	then
-		# Try load the autofs4 module fail if we can't
-		modprobe $MODULE >/dev/null 2>&1
-		if [ $? -eq 1 ]
-		then
-			echo "Error: failed to load autofs4 module."
+	if ! grep -q autofs /proc/filesystems; then
+		# Try to load the autofs4 module and fail if we can't
+		modprobe -q $MODULE >/dev/null 2>&1
+		if [ $? -eq 1 ]; then
+			echo "Error: failed to load $MODULE module."
 			return 1
 		fi
-	elif ([ -f /proc/modules ] && lsmod) | grep -q autofs[^4]
-	then
-		# wrong autofs filesystem module loaded
+	elif ([ -f /proc/modules ] && lsmod) | grep -q autofs[^4]; then
+		# Wrong (old) autofs filesystem module loaded
 		echo
-		echo "Error: autofs kernel module is loaded, autofs4 required"
+		echo "Error: autofs kernel module is loaded, $MODULE required."
 		return 1
 	fi
 
@@ -109,7 +106,7 @@ function restart() {
 
 function reload() {
 	pid=`pidof $prog`
-	if [ -z $pid ]; then
+	if [ -z "$pid" ]; then
 		echo $"$prog not running"
 		RETVAL=1
 	else
@@ -136,6 +133,11 @@ case "$1" in
 	restart)
 		restart
 		;;
+	try-restart)
+		if [ -n "`pidof $prog`" ]; then
+			restart
+		fi
+		;;
 	forcerestart)
 		OPTIONS="$OPTIONS --force"
 		restart
@@ -144,7 +146,7 @@ case "$1" in
 		reload
 		;;
 	*)
-		echo $"Usage: $0 {start|forcestart|stop|restart|forcerestart|reload}"
+		echo $"Usage: $0 {start|forcestart|stop|restart|try-restart|forcerestart|reload}"
 		exit 1;
 		;;
 esac
#1 lore raw

redhat/autofs.init.in

Quoted 2 lines
redhat/autofs.init.in +0 -0

I apologize. This change was untested and obviously wrong:

redhat/autofs.init.in

Quoted 2 lines
redhat/autofs.init.in +1 -0
 	condrestart)
+	try-restart)

Here's the fixed version.

autofs-5.0.5 - add try-restart init script action

Implement try-restart init script action to restart the service only if the service is already running. This action is part of LSB since version 1.9.

While there, fix some typos and adjust coding style for consistency.

redhat/autofs.init.in +10 -13
Index: autofs/redhat/autofs.init.in
===================================================================
@@ -26,7 +26,7 @@ DEVICE="autofs"
 initdir=@@initdir@@
 confdir=@@autofsconfdir@@
 
-test -e $DAEMON || exit 0
+test -x $DAEMON || exit 1
 
 if [ -r $initdir/functions ]; then
 	. $initdir/functions
@@ -36,7 +36,7 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin
 export PATH
 
 #
-# load customized configuation settings
+# load customized configuration settings
 #
 if [ -r $confdir/autofs ]; then
 	. $confdir/autofs
@@ -44,14 +44,12 @@ fi
 
 function start() {
 	# Make sure autofs4 module is loaded
-	if ! grep -q autofs /proc/filesystems
-	then
+	if ! grep -q autofs /proc/filesystems; then
 		echo -n "Loading $MODULE: "
-		# Try load the autofs4 module fail if we can't
-		modprobe $MODULE >/dev/null 2>&1
+		# Try to load the autofs4 module and fail if we can't
+		modprobe -q $MODULE >/dev/null 2>&1
 		RETVAL=$?
-		if [ $RETVAL -eq 1 ]
-		then
+		if [ $RETVAL -eq 1 ]; then
 			failure "Load $MODULE"
 			echo
 			return $RETVAL
@@ -59,8 +57,7 @@ function start() {
 			success "Load $MODULE"
 			echo
 		fi
-	elif ([ -f /proc/modules ] && lsmod) | grep -q autofs[^4]
-	then
+	elif ([ -f /proc/modules ] && lsmod) | grep -q autofs[^4]; then
 		RETVAL=1
 		failure "Load $MODULE"
 		echo
@@ -129,7 +126,7 @@ function reload() {
 		return $RETVAL
 	fi
 	pid=`pidof $prog`
-	if [ -z $pid ]; then
+	if [ -z "$pid" ]; then
 		echo $"$prog not running"
 		RETVAL=1
 	else
@@ -166,13 +163,13 @@ case "$1" in
 	reload)
 		reload
 		;;
-	condrestart)
+	condrestart|try-restart)
 		if [ -f /var/lock/subsys/autofs ]; then
 			restart
 		fi
 		;;
 	*)
-		echo $"Usage: $0 {start|forcestart|stop|status|restart|forcerestart|reload|condrestart}"
+		echo $"Usage: $0 {start|forcestart|stop|status|restart|forcerestart|reload|condrestart|try-restart}"
 		exit 1;
 		;;
 esac
samples/rc.autofs.in +17 -15
Index: autofs/samples/rc.autofs.in
===================================================================
@@ -24,13 +24,13 @@ MODULE="autofs4"
 DEVICE="autofs"
 confdir=@@autofsconfdir@@
 
-test -e $DAEMON || exit 0
+test -x $DAEMON || exit 1
 
 PATH=/sbin:/usr/sbin:/bin:/usr/bin
 export PATH
 
 #
-# load customized configuation settings
+# load customized configuration settings
 #
 if [ -r $confdir/autofs ]; then
 	. $confdir/autofs
@@ -40,20 +40,17 @@ function start() {
 	echo -n "Starting $prog: "
 
 	# Make sure autofs4 module is loaded
-	if ! grep -q autofs /proc/filesystems
-	then
-		# Try load the autofs4 module fail if we can't
-		modprobe $MODULE >/dev/null 2>&1
-		if [ $? -eq 1 ]
-		then
-			echo "Error: failed to load autofs4 module."
+	if ! grep -q autofs /proc/filesystems; then
+		# Try to load the autofs4 module and fail if we can't
+		modprobe -q $MODULE >/dev/null 2>&1
+		if [ $? -eq 1 ]; then
+			echo "Error: failed to load $MODULE module."
 			return 1
 		fi
-	elif ([ -f /proc/modules ] && lsmod) | grep -q autofs[^4]
-	then
-		# wrong autofs filesystem module loaded
+	elif ([ -f /proc/modules ] && lsmod) | grep -q autofs[^4]; then
+		# Wrong (old) autofs filesystem module loaded
 		echo
-		echo "Error: autofs kernel module is loaded, autofs4 required"
+		echo "Error: autofs kernel module is loaded, $MODULE required."
 		return 1
 	fi
 
@@ -109,7 +106,7 @@ function restart() {
 
 function reload() {
 	pid=`pidof $prog`
-	if [ -z $pid ]; then
+	if [ -z "$pid" ]; then
 		echo $"$prog not running"
 		RETVAL=1
 	else
@@ -136,6 +133,11 @@ case "$1" in
 	restart)
 		restart
 		;;
+	try-restart)
+		if [ -n "`pidof $prog`" ]; then
+			restart
+		fi
+		;;
 	forcerestart)
 		OPTIONS="$OPTIONS --force"
 		restart
@@ -144,7 +146,7 @@ case "$1" in
 		reload
 		;;
 	*)
-		echo $"Usage: $0 {start|forcestart|stop|restart|forcerestart|reload}"
+		echo $"Usage: $0 {start|forcestart|stop|restart|try-restart|forcerestart|reload}"
 		exit 1;
 		;;
 esac