public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] syslog-lib.sh: Use lib to restart syslog service
@ 2013-07-09  9:51 Peng Haitao
  2013-07-09 11:42 ` chrubis
  2013-07-09 11:44 ` Jan Stancek
  0 siblings, 2 replies; 3+ messages in thread
From: Peng Haitao @ 2013-07-09  9:51 UTC (permalink / raw)
  To: ltp-list

Use restart_daemon() to restart syslog service.

Signed-off-by: Peng Haitao <penght@cn.fujitsu.com>
---
 testcases/kernel/syscalls/syslog/syslog-lib.sh | 74 +++++---------------------
 testcases/lib/cmdlib.sh                        |  8 +++
 2 files changed, 20 insertions(+), 62 deletions(-)

diff --git a/testcases/kernel/syscalls/syslog/syslog-lib.sh b/testcases/kernel/syscalls/syslog/syslog-lib.sh
index c912d61..9bd411a 100755
--- a/testcases/kernel/syscalls/syslog/syslog-lib.sh
+++ b/testcases/kernel/syscalls/syslog/syslog-lib.sh
@@ -23,22 +23,6 @@ readonly MAILLOG=/var/log/maillog
 # Signals to trap.
 readonly TRAP_SIGS="1 2 3 6 11 15"
 
-# configuration file for syslog or syslog-ng
-CONFIG_FILE=""
-
-# rsyslogd .conf specific args.
-RSYSLOG_CONFIG=
-
-# Command to restart syslog daemon.
-SYSLOG_RESTART_COMMAND=
-
-# 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
 
@@ -75,46 +59,6 @@ setup()
 		tst_resm TBROK "Testing is terminating due to a signal"
 		cleanup 1' $TRAP_SIGS || exit 1
 
-	# Check to see if syslogd or syslog-ng exists
-	if [ -e /sbin/syslogd ]; then
-		CONFIG_FILE="/etc/syslog.conf"
-		SYSLOG_INIT_SCRIPT="/etc/init.d/sysklogd"
-	elif command -v syslog-ng >/dev/null 2>&1; then
-		CONFIG_FILE="/etc/syslog-ng/syslog-ng.conf"
-		SYSLOG_INIT_SCRIPT="/etc/init.d/syslog-ng"
-	elif command -v rsyslogd >/dev/null 2>&1; then
-		CONFIG_FILE="/etc/rsyslog.conf"
-		SYSLOG_INIT_SCRIPT="/etc/init.d/rsyslog"
-		RSYSLOG_CONFIG='$ModLoad imuxsock.so'
-	else
-		tst_resm TCONF "couldn't find syslogd, syslog-ng, or rsyslogd"
-		cleanup	0
-	fi
-
-	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
-	fi
-
-	if [ -z "$SYSLOG_RESTART_COMMAND" ]; then
-		tst_resm TBROK "Don't know how to restart $SVCNAME"
-		cleanup 1
-	fi
-
 	# Back up configuration file
 	if [ -f "$CONFIG_FILE" ]; then
 		# Pause if another LTP syslog test is running
@@ -152,14 +96,20 @@ restart_syslog_daemon()
 		cleanup_command=$1
 	fi
 
-	tst_resm TINFO "restarting syslog daemon via $SYSLOG_RESTART_COMMAND"
+	tst_resm TINFO "restarting syslog daemon"
 
-	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.
-		sleep 2
+	if [ -n "$SYSLOG_DAEMON" ]; then
+		restart_daemon $SYSLOG_DAEMON
+		if [ $? -eq 0 ]; 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.
+			sleep 2
+		else
+			$cleanup_command
+		fi
 	else
+		tst_resm TBROK "Couldn't find syslogd, syslog-ng or rsyslogd"
 		$cleanup_command
 	fi
 }
diff --git a/testcases/lib/cmdlib.sh b/testcases/lib/cmdlib.sh
index d6f43d2..23d5723 100644
--- a/testcases/lib/cmdlib.sh
+++ b/testcases/lib/cmdlib.sh
@@ -158,13 +158,21 @@ else
 	HAVE_SYSTEMCTL=0
 fi
 
+# Configuration file for syslog, syslog-ng or rsyslogd
+CONFIG_FILE=""
+# rsyslog.conf specific args.
+RSYSLOG_CONFIG=""
 # Check to see if syslogd, syslog-ng or rsyslogd exists
 SYSLOG_DAEMON=""
 if command -v syslogd >/dev/null 2>&1; then
+	CONFIG_FILE="/etc/syslog.conf"
 	SYSLOG_DAEMON="syslog"
 elif command -v syslog-ng >/dev/null 2>&1; then
+	CONFIG_FILE="/etc/syslog-ng/syslog-ng.conf"
 	SYSLOG_DAEMON="syslog-ng"
 elif command -v rsyslogd >/dev/null 2>&1; then
+	CONFIG_FILE="/etc/rsyslog.conf"
+	RSYSLOG_CONFIG='$ModLoad imuxsock.so'
 	SYSLOG_DAEMON="rsyslog"
 fi
 
-- 
1.8.3.1


------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH] syslog-lib.sh: Use lib to restart syslog service
  2013-07-09  9:51 [LTP] [PATCH] syslog-lib.sh: Use lib to restart syslog service Peng Haitao
@ 2013-07-09 11:42 ` chrubis
  2013-07-09 11:44 ` Jan Stancek
  1 sibling, 0 replies; 3+ messages in thread
From: chrubis @ 2013-07-09 11:42 UTC (permalink / raw)
  To: Peng Haitao; +Cc: ltp-list

Hi!
> +# Configuration file for syslog, syslog-ng or rsyslogd
> +CONFIG_FILE=""
> +# rsyslog.conf specific args.
> +RSYSLOG_CONFIG=""
>  # Check to see if syslogd, syslog-ng or rsyslogd exists
>  SYSLOG_DAEMON=""
>  if command -v syslogd >/dev/null 2>&1; then
> +	CONFIG_FILE="/etc/syslog.conf"
>  	SYSLOG_DAEMON="syslog"
>  elif command -v syslog-ng >/dev/null 2>&1; then
> +	CONFIG_FILE="/etc/syslog-ng/syslog-ng.conf"
>  	SYSLOG_DAEMON="syslog-ng"
>  elif command -v rsyslogd >/dev/null 2>&1; then
> +	CONFIG_FILE="/etc/rsyslog.conf"
> +	RSYSLOG_CONFIG='$ModLoad imuxsock.so'
>  	SYSLOG_DAEMON="rsyslog"
>  fi

I think that the configuration related code should have
stayed in the testcase (as it is not a code to be reused).

So what I would do is to detect the syslog in the lib
and then use switch on the SYSLOG_DAEMON variable to set
the rest of the variables in the test code.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH] syslog-lib.sh: Use lib to restart syslog service
  2013-07-09  9:51 [LTP] [PATCH] syslog-lib.sh: Use lib to restart syslog service Peng Haitao
  2013-07-09 11:42 ` chrubis
@ 2013-07-09 11:44 ` Jan Stancek
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Stancek @ 2013-07-09 11:44 UTC (permalink / raw)
  To: Peng Haitao; +Cc: ltp-list



----- Original Message -----
> From: "Peng Haitao" <penght@cn.fujitsu.com>
> To: ltp-list@lists.sourceforge.net
> Sent: Tuesday, 9 July, 2013 11:51:12 AM
> Subject: [LTP] [PATCH] syslog-lib.sh: Use lib to restart syslog service
> 
> Use restart_daemon() to restart syslog service.
> 
> Signed-off-by: Peng Haitao <penght@cn.fujitsu.com>
> ---
>  testcases/kernel/syscalls/syslog/syslog-lib.sh | 74
>  +++++---------------------
>  testcases/lib/cmdlib.sh                        |  8 +++
>  2 files changed, 20 insertions(+), 62 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/syslog/syslog-lib.sh
> b/testcases/kernel/syscalls/syslog/syslog-lib.sh
> index c912d61..9bd411a 100755
> --- a/testcases/kernel/syscalls/syslog/syslog-lib.sh
> +++ b/testcases/kernel/syscalls/syslog/syslog-lib.sh
> @@ -23,22 +23,6 @@ readonly MAILLOG=/var/log/maillog
>  # Signals to trap.
>  readonly TRAP_SIGS="1 2 3 6 11 15"
>  
> -# configuration file for syslog or syslog-ng
> -CONFIG_FILE=""
> -
> -# rsyslogd .conf specific args.
> -RSYSLOG_CONFIG=
> -
> -# Command to restart syslog daemon.
> -SYSLOG_RESTART_COMMAND=
> -
> -# 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
>  
> @@ -75,46 +59,6 @@ setup()
>  		tst_resm TBROK "Testing is terminating due to a signal"
>  		cleanup 1' $TRAP_SIGS || exit 1
>  
> -	# Check to see if syslogd or syslog-ng exists
> -	if [ -e /sbin/syslogd ]; then
> -		CONFIG_FILE="/etc/syslog.conf"
> -		SYSLOG_INIT_SCRIPT="/etc/init.d/sysklogd"
> -	elif command -v syslog-ng >/dev/null 2>&1; then
> -		CONFIG_FILE="/etc/syslog-ng/syslog-ng.conf"
> -		SYSLOG_INIT_SCRIPT="/etc/init.d/syslog-ng"
> -	elif command -v rsyslogd >/dev/null 2>&1; then
> -		CONFIG_FILE="/etc/rsyslog.conf"
> -		SYSLOG_INIT_SCRIPT="/etc/init.d/rsyslog"
> -		RSYSLOG_CONFIG='$ModLoad imuxsock.so'
> -	else
> -		tst_resm TCONF "couldn't find syslogd, syslog-ng, or rsyslogd"
> -		cleanup	0
> -	fi
> -
> -	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
> -	fi
> -
> -	if [ -z "$SYSLOG_RESTART_COMMAND" ]; then
> -		tst_resm TBROK "Don't know how to restart $SVCNAME"
> -		cleanup 1
> -	fi
> -
>  	# Back up configuration file
>  	if [ -f "$CONFIG_FILE" ]; then
>  		# Pause if another LTP syslog test is running
> @@ -152,14 +96,20 @@ restart_syslog_daemon()
>  		cleanup_command=$1
>  	fi
>  
> -	tst_resm TINFO "restarting syslog daemon via $SYSLOG_RESTART_COMMAND"
> +	tst_resm TINFO "restarting syslog daemon"
>  
> -	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.
> -		sleep 2
> +	if [ -n "$SYSLOG_DAEMON" ]; then
> +		restart_daemon $SYSLOG_DAEMON
> +		if [ $? -eq 0 ]; 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.
> +			sleep 2
> +		else
> +			$cleanup_command
> +		fi
>  	else
> +		tst_resm TBROK "Couldn't find syslogd, syslog-ng or rsyslogd"
>  		$cleanup_command
>  	fi
>  }
> diff --git a/testcases/lib/cmdlib.sh b/testcases/lib/cmdlib.sh
> index d6f43d2..23d5723 100644
> --- a/testcases/lib/cmdlib.sh
> +++ b/testcases/lib/cmdlib.sh
> @@ -158,13 +158,21 @@ else
>  	HAVE_SYSTEMCTL=0
>  fi
>  
> +# Configuration file for syslog, syslog-ng or rsyslogd
> +CONFIG_FILE=""

Hi,

This looks too generic. What if library need to pass config files for 2 libraries?

> +# rsyslog.conf specific args.
> +RSYSLOG_CONFIG=""
>  # Check to see if syslogd, syslog-ng or rsyslogd exists
>  SYSLOG_DAEMON=""
>  if command -v syslogd >/dev/null 2>&1; then
> +	CONFIG_FILE="/etc/syslog.conf"
>  	SYSLOG_DAEMON="syslog"
>  elif command -v syslog-ng >/dev/null 2>&1; then
> +	CONFIG_FILE="/etc/syslog-ng/syslog-ng.conf"
>  	SYSLOG_DAEMON="syslog-ng"
>  elif command -v rsyslogd >/dev/null 2>&1; then
> +	CONFIG_FILE="/etc/rsyslog.conf"
> +	RSYSLOG_CONFIG='$ModLoad imuxsock.so'

RSYSLOG_CONFIG is specific to syscalls/syslog tests. Is user of this library expected
to care about how minimum config looks like for rsyslog?

Regards,
Jan

>  	SYSLOG_DAEMON="rsyslog"
>  fi
>  
> --
> 1.8.3.1
> 
> 
> ------------------------------------------------------------------------------
> See everything from the browser to the database with AppDynamics
> Get end-to-end visibility with application monitoring from AppDynamics
> Isolate bottlenecks and diagnose root cause in seconds.
> Start your free trial of AppDynamics Pro today!
> http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
> _______________________________________________
> Ltp-list mailing list
> Ltp-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ltp-list
> 

------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-07-09 11:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-09  9:51 [LTP] [PATCH] syslog-lib.sh: Use lib to restart syslog service Peng Haitao
2013-07-09 11:42 ` chrubis
2013-07-09 11:44 ` Jan Stancek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox