init.d/ scripts may not be available on distros
using systemd, for example Fedora16.

This patch is using 'systemctl' to restart syslog daemon
on distros running systemd. If systemctl is not available
it falls back to directly calling init script.

Also it drops few upstart TODO comments, current code
works OK with upstart (tested on RHEL6).

Signed-off-by: Jan Stancek <[email protected]>
---
testcases/kernel/syscalls/syslog/syslog-lib.sh | 40 +++++++++++++----------
 1 files changed, 23 insertions(+), 17 deletions(-)


diff --git a/testcases/kernel/syscalls/syslog/syslog-lib.sh b/testcases/kernel/syscalls/syslog/syslog-lib.sh
index 91a2e62..3d0c189 100755
--- a/testcases/kernel/syscalls/syslog/syslog-lib.sh
+++ b/testcases/kernel/syscalls/syslog/syslog-lib.sh
@@ -29,11 +29,15 @@ CONFIG_FILE=""
 # rsyslogd .conf specific args.
 RSYSLOG_CONFIG=
 
-# Command for syslog daemon.
-SYSLOG_COMMAND=
+# Command to restart syslog daemon.
+SYSLOG_RESTART_COMMAND=
 
-# Args to pass to $SYSLOG_COMMAND when restarting the daemon.
-SYSLOG_RESTART_COMMAND_ARGS=
+# running under systemd?
+if command -v systemctl >/dev/null 2>&1; then
+	HAVE_SYSTEMCTL=1
+else
+	HAVE_SYSTEMCTL=0
+fi
 
 # number of seconds to wait for another syslog test to complete
 WAIT_COUNT=60
@@ -82,31 +86,33 @@ setup()
 		CONFIG_FILE="/etc/rsyslog.conf"
 		SYSLOG_INIT_SCRIPT="/etc/init.d/rsyslog"
 		RSYSLOG_CONFIG='$ModLoad imuxsock.so'
-	#elif <detect-upstart-jobfile-here>; then
-		# TODO: upstart
 	else
 		tst_resm TCONF "couldn't find syslogd, syslog-ng, or rsyslogd"
 		cleanup	0
 	fi
 
-	if [ -z "$SYSLOG_INIT_SCRIPT" ]; then
-		# TODO: upstart
-		:
+	SVCNAME=$(basename $SYSLOG_INIT_SCRIPT)
+	if [ $HAVE_SYSTEMCTL == 1 ]; then
+		for svc in "$SVCNAME" "syslog"; do
+			if systemctl is-enabled $svc.service >/dev/null 2>&1; then
+				SYSLOG_RESTART_COMMAND="systemctl restart $svc.service"
+				break
+			fi
+		done
 	else
 		# Fallback to /etc/init.d/syslog if $SYSLOG_INIT_SCRIPT
 		# doesn't exist.
 		for SYSLOG_INIT_SCRIPT in "$SYSLOG_INIT_SCRIPT" "/etc/init.d/syslog"; do 
 			if [ -x "$SYSLOG_INIT_SCRIPT" ]; then
+				SYSLOG_RESTART_COMMAND="$SYSLOG_INIT_SCRIPT restart"
 				break
 			fi
 		done
-		if [ ! -x "$SYSLOG_INIT_SCRIPT" ]; then
-			tst_resm TBROK "$SYSLOG_INIT_SCRIPT - no such script"
-			cleanup 1
-		fi
+	fi
 
-		SYSLOG_COMMAND=$SYSLOG_INIT_SCRIPT
-		SYSLOG_RESTART_COMMAND_ARGS=restart
+	if [ -z "$SYSLOG_RESTART_COMMAND" ]; then
+		tst_resm TBROK "Don't know how to restart $SVCNAME"
+		cleanup 1
 	fi
 
 	# Back up configuration file
@@ -146,9 +152,9 @@ restart_syslog_daemon()
 		cleanup_command=$1
 	fi
 
-	tst_resm TINFO "restarting syslog daemon via $SYSLOG_COMMAND $SYSLOG_RESTART_COMMAND_ARGS"
+	tst_resm TINFO "restarting syslog daemon via $SYSLOG_RESTART_COMMAND"
 
-	if $SYSLOG_COMMAND $SYSLOG_RESTART_COMMAND_ARGS >/dev/null 2>&1; then
+	if $SYSLOG_RESTART_COMMAND >/dev/null 2>&1; then
 		# XXX: this really shouldn't exist; if *syslogd isn't ready
 		# once the restart directive has been issued, then it needs to
 		# be fixed.

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to