packages: rsyslog/rsyslog.init - check config before start/restart

arekm arekm at pld-linux.org
Mon Mar 7 14:44:54 CET 2011


Author: arekm                        Date: Mon Mar  7 13:44:54 2011 GMT
Module: packages                      Tag: HEAD
---- Log message:
- check config before start/restart

---- Files affected:
packages/rsyslog:
   rsyslog.init (1.4 -> 1.5) 

---- Diffs:

================================================================
Index: packages/rsyslog/rsyslog.init
diff -u packages/rsyslog/rsyslog.init:1.4 packages/rsyslog/rsyslog.init:1.5
--- packages/rsyslog/rsyslog.init:1.4	Fri Nov 26 19:57:18 2010
+++ packages/rsyslog/rsyslog.init	Mon Mar  7 14:44:48 2011
@@ -19,6 +19,36 @@
 	. /etc/sysconfig/rsyslog
 fi
 
+configtest() {
+	rsyslogd $SYSLOGD_OPTIONS -N1 -i /var/run/rsyslogd-syntaxcheck.pid
+	return $?
+}
+
+checkconfig() {
+	local details=${1:-0}
+
+	if [ $details = 1 ]; then
+		show "Checking %s configuration" "rsyslog"; busy
+		local out
+		out=$(configtest 2>&1)
+		RETVAL=$?
+		if [ $RETVAL = 0 ]; then
+			ok
+		else
+			fail
+		fi
+		[ "$out" ] && echo >&2 "$out"
+	else
+		configtest >/dev/null 2>&1
+		RETVAL=$?
+		if [ $RETVAL != 0 ]; then
+			show "Checking %s configuration" "rsyslog"; fail
+			nls 'Configuration test failed. See details with %s "checkconfig"' $0
+			exit $RETVAL
+		fi
+	fi
+}
+
 start() {
 	if [ ! -f /var/lock/subsys/rsyslog ]; then
 		umask 077
@@ -64,28 +94,33 @@
 
 RETVAL=0
 case "$1" in
-  start)
-        start
-        ;;
-  stop)
-        stop
-        ;;
-  restart)
-        stop
-	start
-        ;;
-  try-restart)
-	condrestart 0
-	;;
-  reload|force-reload)
-	reload
-	;;
-  status)
-        status rsyslogd
-        ;;
-  *)
-        msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
-        exit 3
+	start)
+		checkconfig
+		start
+		;;
+	stop)
+		stop
+		;;
+	restart)
+		checkconfig
+		stop
+		start
+		;;
+	try-restart)
+		condrestart 0
+		;;
+	reload|force-reload)
+		reload
+		;;
+	checkconfig|configtest)
+		checkconfig 1
+		;;
+	status)
+		status rsyslogd
+		;;
+	*)
+		msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}"
+		exit 3
 esac
 
 exit $RETVAL
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/rsyslog/rsyslog.init?r1=1.4&r2=1.5&f=u



More information about the pld-cvs-commit mailing list