SVN: rc-scripts/trunk/rc.d/init.d/template.init

glen glen at pld-linux.org
Sat Jul 25 21:24:32 CEST 2009


Author: glen
Date: Sat Jul 25 21:24:32 2009
New Revision: 10425

Modified:
   rc-scripts/trunk/rc.d/init.d/template.init
Log:
- add checkconfig action sample

Modified: rc-scripts/trunk/rc.d/init.d/template.init
==============================================================================
--- rc-scripts/trunk/rc.d/init.d/template.init	(original)
+++ rc-scripts/trunk/rc.d/init.d/template.init	Sat Jul 25 21:24:32 2009
@@ -37,6 +37,40 @@
 	exit 0
 fi
 
+# configtest itself
+configtest() {
+	local rc out
+
+	# capture program output from configtest, print it out only on error
+	out=`/usr/sbin/<service> -t 2>&1`; rc=$?
+	if [ $rc -gt 0 ]; then
+		echo >&2 "$out"
+	fi
+	return $rc
+}
+
+# wrapper for configtest:
+checkconfig() {
+	local details=${1:-0}
+
+	if [ $details = 1 ]; then
+		# run config test and display report (status action)
+		show "Checking %s configuration" "<service_name>"; busy; echo
+		configtest
+		RETVAL=$?
+	else
+		# run config test and abort with nice message if failed
+		# (for actions checking status before action).
+		configtest >/dev/null 2>&1
+		RETVAL=$?
+		if [ $RETVAL != 0 ]; then
+			show "Checking %s configuration" "<service_name>"; fail
+			nls 'Configuration test failed. See details with %s "checkconfig"' $0
+			exit $RETVAL
+		fi
+	fi
+}
+
 start() {
 	# Check if the service is already running?
 	if [ -f /var/lock/subsys/<service> ]; then
@@ -44,6 +78,7 @@
 		return
 	fi
 
+	checkconfig
 	msg_starting "<service_name>"
 	daemon /usr/sbin/<service>
 	RETVAL=$?
@@ -70,6 +105,7 @@
 		return
 	fi
 
+	checkconfig
 	msg_reloading "<service_name>"
 	killproc <service> -HUP
 	killproc --pidfile /var/run/<service>.pid <service> -HUP
@@ -83,6 +119,7 @@
 		return
 	fi
 
+	checkconfig
 	stop
 	start
 }
@@ -97,6 +134,7 @@
   	stop
 	;;
   restart)
+	checkconfig
 	stop
 	start
 	;;
@@ -112,12 +150,15 @@
   force-reload)
 	condrestart 7
 	;;
+  checkconfig)
+	checkconfig 1
+	;;
   status)
 	status <service>
 	RETVAL=$?
 	;;
   *)
-	msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
+	msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}"
 	exit 3
 esac
 


More information about the pld-cvs-commit mailing list