public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/4] cmdlib.sh: Add four functions of controlling daemon
@ 2012-12-04  7:21 Peng Haitao
  2012-12-04  7:21 ` [LTP] [PATCH 2/4] runnetnstest.sh: fix a fail of vsftpd is disabled Peng Haitao
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Peng Haitao @ 2012-12-04  7:21 UTC (permalink / raw)
  To: ltp-list

Add four functions of controlling daemon:
  - start_daemon
  - stop_daemon
  - status_daemon
  - restart_daemon

Signed-off-by: Peng Haitao <penght@cn.fujitsu.com>
---
 testcases/lib/cmdlib.sh | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/testcases/lib/cmdlib.sh b/testcases/lib/cmdlib.sh
index 6aeb10f..b7eee1a 100644
--- a/testcases/lib/cmdlib.sh
+++ b/testcases/lib/cmdlib.sh
@@ -150,3 +150,46 @@ is_root()
 TCID=${TCID:=}
 [ -z "$TCID" ] && TCID=${0##*/}
 TC=$(echo "$TCID" | awk '{ sub( /[0-9]+$/,""); print; }')
+
+# running under systemd?
+if command -v systemctl >/dev/null 2>&1; then
+	HAVE_SYSTEMCTL=1
+else
+	HAVE_SYSTEMCTL=0
+fi
+
+start_daemon()
+{
+	if [ $HAVE_SYSTEMCTL -eq 1 ]; then
+		systemctl start $1.service > /dev/null 2>&1
+	else
+		service $1 start > /dev/null 2>&1
+	fi
+}
+
+stop_daemon()
+{
+	if [ $HAVE_SYSTEMCTL -eq 1 ]; then
+		systemctl stop $1.service > /dev/null 2>&1
+	else
+		service $1 stop > /dev/null 2>&1
+	fi
+}
+
+status_daemon()
+{
+	if [ $HAVE_SYSTEMCTL -eq 1 ]; then
+		systemctl status $1.service > /dev/null 2>&1
+	else
+		service $1 status > /dev/null 2>&1
+	fi
+}
+
+restart_daemon()
+{
+	if [ $HAVE_SYSTEMCTL -eq 1 ]; then
+		systemctl start $1.service > /dev/null 2>&1
+	else
+		service $1 start > /dev/null 2>&1
+	fi
+}
-- 
1.8.0


------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 2/4] runnetnstest.sh: fix a fail of vsftpd is disabled
  2012-12-04  7:21 [LTP] [PATCH 1/4] cmdlib.sh: Add four functions of controlling daemon Peng Haitao
@ 2012-12-04  7:21 ` Peng Haitao
  2012-12-07  7:50   ` Wanlong Gao
  2012-12-04  7:21 ` [LTP] [PATCH 3/4] at_allow01: Use lib to restart atd service Peng Haitao
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Peng Haitao @ 2012-12-04  7:21 UTC (permalink / raw)
  To: ltp-list

When vsftpd is disabled, runnetnstest.sh should start vsftpd first.

Signed-off-by: Peng Haitao <penght@cn.fujitsu.com>
---
 testcases/kernel/containers/netns/runnetnstest.sh | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/testcases/kernel/containers/netns/runnetnstest.sh b/testcases/kernel/containers/netns/runnetnstest.sh
index d2a7fec..fb494a2 100755
--- a/testcases/kernel/containers/netns/runnetnstest.sh
+++ b/testcases/kernel/containers/netns/runnetnstest.sh
@@ -106,6 +106,15 @@ echo
 #fi
 #echo
 
+. cmdlib.sh
+flag=0
+
+status_daemon vsftpd
+if [ $? -ne 0 ]; then
+	start_daemon vsftpd
+	flag=1
+fi
+
 par_chld_ftp
 rc=$?
 if [ $rc -ne 0 ]; then
@@ -115,5 +124,10 @@ if [ $rc -ne 0 ]; then
 else
    echo "par_chld_ftp: PASS"
 fi
+
+if [ $flag -eq 1 ]; then
+	stop_daemon vsftpd
+fi
+
 echo
 exit $exit_code
-- 
1.8.0


------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 3/4] at_allow01: Use lib to restart atd service
  2012-12-04  7:21 [LTP] [PATCH 1/4] cmdlib.sh: Add four functions of controlling daemon Peng Haitao
  2012-12-04  7:21 ` [LTP] [PATCH 2/4] runnetnstest.sh: fix a fail of vsftpd is disabled Peng Haitao
@ 2012-12-04  7:21 ` Peng Haitao
  2012-12-04  7:39   ` Caspar Zhang
  2012-12-04  7:21 ` [LTP] [PATCH 4/4] at_deny01: " Peng Haitao
  2012-12-07  7:50 ` [LTP] [PATCH 1/4] cmdlib.sh: Add four functions of controlling daemon Wanlong Gao
  3 siblings, 1 reply; 10+ messages in thread
From: Peng Haitao @ 2012-12-04  7:21 UTC (permalink / raw)
  To: ltp-list

Use restart_daemon() to restart atd service.

Signed-off-by: Peng Haitao <penght@cn.fujitsu.com>
---
 testcases/commands/at/at_allow01 | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/testcases/commands/at/at_allow01 b/testcases/commands/at/at_allow01
index 43b3428..ad4f733 100755
--- a/testcases/commands/at/at_allow01
+++ b/testcases/commands/at/at_allow01
@@ -80,19 +80,8 @@ do_setup()
 		exit 1
 	fi
 
-	# running under systemd?
-	if command -v systemctl >/dev/null 2>&1; then
-		HAVE_SYSTEMCTL=true
-	else
-		HAVE_SYSTEMCTL=false
-	fi
-
-	# Restart atd daemon.
-	if $HAVE_SYSTEMCTL; then
-		systemctl restart atd.service
-	else
-		/etc/init.d/atd restart
-	fi
+	. cmdlib.sh
+	restart_daemon atd
 }
 
 #-----------------------------------------------------------------------
-- 
1.8.0


------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 4/4] at_deny01: Use lib to restart atd service
  2012-12-04  7:21 [LTP] [PATCH 1/4] cmdlib.sh: Add four functions of controlling daemon Peng Haitao
  2012-12-04  7:21 ` [LTP] [PATCH 2/4] runnetnstest.sh: fix a fail of vsftpd is disabled Peng Haitao
  2012-12-04  7:21 ` [LTP] [PATCH 3/4] at_allow01: Use lib to restart atd service Peng Haitao
@ 2012-12-04  7:21 ` Peng Haitao
  2012-12-07  7:50 ` [LTP] [PATCH 1/4] cmdlib.sh: Add four functions of controlling daemon Wanlong Gao
  3 siblings, 0 replies; 10+ messages in thread
From: Peng Haitao @ 2012-12-04  7:21 UTC (permalink / raw)
  To: ltp-list

Use restart_daemon() to restart atd service.

Signed-off-by: Peng Haitao <penght@cn.fujitsu.com>
---
 testcases/commands/at/at_deny01 | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/testcases/commands/at/at_deny01 b/testcases/commands/at/at_deny01
index fe3dce0..059eb08 100755
--- a/testcases/commands/at/at_deny01
+++ b/testcases/commands/at/at_deny01
@@ -86,19 +86,8 @@ do_setup()
 		exit 1
 	fi
 
-	# running under systemd?
-	if command -v systemctl >/dev/null 2>&1; then
-		HAVE_SYSTEMCTL=true
-	else
-		HAVE_SYSTEMCTL=false
-	fi
-
-	# Restart atd daemon.
-	if $HAVE_SYSTEMCTL; then
-		systemctl restart atd.service
-	else
-		/etc/init.d/atd restart
-	fi
+	. cmdlib.sh
+	restart_daemon atd
 }
 
 #-----------------------------------------------------------------------
-- 
1.8.0


------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 3/4] at_allow01: Use lib to restart atd service
  2012-12-04  7:21 ` [LTP] [PATCH 3/4] at_allow01: Use lib to restart atd service Peng Haitao
@ 2012-12-04  7:39   ` Caspar Zhang
  2012-12-04  9:17     ` Peng Haitao
  2012-12-06 14:24     ` chrubis
  0 siblings, 2 replies; 10+ messages in thread
From: Caspar Zhang @ 2012-12-04  7:39 UTC (permalink / raw)
  To: Peng Haitao; +Cc: ltp-list

On 12/04/2012 03:21 PM, Peng Haitao wrote:
> + 84» .·cmdlib.sh

Patch series looks good to me except this.

sourcing a lib inside a function seems not so good. Yet I don't see any 
code style rules telling which is the correct place to put a shell lib 
source (commonly I think it would be the top in the file)

Thanks,
Caspar

> + 85» restart_daemon·atd




------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 3/4] at_allow01: Use lib to restart atd service
  2012-12-04  7:39   ` Caspar Zhang
@ 2012-12-04  9:17     ` Peng Haitao
  2012-12-05  4:40       ` Caspar Zhang
  2012-12-06 14:24     ` chrubis
  1 sibling, 1 reply; 10+ messages in thread
From: Peng Haitao @ 2012-12-04  9:17 UTC (permalink / raw)
  To: Caspar Zhang; +Cc: ltp-list


On 12/04/2012 03:39 PM, Caspar Zhang wrote:
> On 12/04/2012 03:21 PM, Peng Haitao wrote:
>> + 84» .·cmdlib.sh
> 
> Patch series looks good to me except this.
> 
> sourcing a lib inside a function seems not so good. Yet I don't see any code style rules telling which is the correct place to put a shell lib source (commonly I think it would be the top in the file)
> 
	
Yeah. I think so, too. 
If sourcing a lib in the top of the file, the case will fail.
Because the case will use su xxx -lc to execute itself in xxx's home directory.
But cmdlib.sh is in /opt/ltp/testcases/bin/, not in xxx's home directory.


This has another method, add the following content in top of the file:

if [ "$(id -ru)" = 0 ]; then
        . cmdlib.sh
fi

I think add inside a function is simple:)
If you think add in top of the file will better, I will resend it.
Thanks.

-- 
Best Regards,
Peng

> Thanks,
> Caspar
> 
>> + 85» restart_daemon·atd
> 
> 
> 
> 

-- 
Best Regards,
Peng

------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 3/4] at_allow01: Use lib to restart atd service
  2012-12-04  9:17     ` Peng Haitao
@ 2012-12-05  4:40       ` Caspar Zhang
  0 siblings, 0 replies; 10+ messages in thread
From: Caspar Zhang @ 2012-12-05  4:40 UTC (permalink / raw)
  To: Peng Haitao; +Cc: ltp-list

On 12/04/2012 05:17 PM, Peng Haitao wrote:
>
> On 12/04/2012 03:39 PM, Caspar Zhang wrote:
>> On 12/04/2012 03:21 PM, Peng Haitao wrote:
>>> + 84» .·cmdlib.sh
>>
>> Patch series looks good to me except this.
>>
>> sourcing a lib inside a function seems not so good. Yet I don't see any code style rules telling which is the correct place to put a shell lib source (commonly I think it would be the top in the file)
>>
> 	
> Yeah. I think so, too.
> If sourcing a lib in the top of the file, the case will fail.
> Because the case will use su xxx -lc to execute itself in xxx's home directory.
> But cmdlib.sh is in /opt/ltp/testcases/bin/, not in xxx's home directory.
>
>
> This has another method, add the following content in top of the file:
>
> if [ "$(id -ru)" = 0 ]; then
>          . cmdlib.sh
> fi
>
> I think add inside a function is simple:)
> If you think add in top of the file will better, I will resend it.
> Thanks.
>
I'm OK if the simpler way won't cause confusion :)

Caspar

------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 3/4] at_allow01: Use lib to restart atd service
  2012-12-04  7:39   ` Caspar Zhang
  2012-12-04  9:17     ` Peng Haitao
@ 2012-12-06 14:24     ` chrubis
  1 sibling, 0 replies; 10+ messages in thread
From: chrubis @ 2012-12-06 14:24 UTC (permalink / raw)
  To: Caspar Zhang; +Cc: ltp-list

Hi!
> > + 84?? .??cmdlib.sh
> 
> Patch series looks good to me except this.

The patch series looks really good.

> sourcing a lib inside a function seems not so good. Yet I don't see any 
> code style rules telling which is the correct place to put a shell lib 
> source (commonly I think it would be the top in the file)

It's always better to include the bash library first so that your
variables are not rewritten by these used in the library. I've seen
cases where this was a issue (one test included a file from init scripts
which is different in diferent version of distribution and in one case
the name clashed) and the test was broken because the file wasn't
included at the top.

So actually this is not hard requirement but rather a good practice.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 1/4] cmdlib.sh: Add four functions of controlling daemon
  2012-12-04  7:21 [LTP] [PATCH 1/4] cmdlib.sh: Add four functions of controlling daemon Peng Haitao
                   ` (2 preceding siblings ...)
  2012-12-04  7:21 ` [LTP] [PATCH 4/4] at_deny01: " Peng Haitao
@ 2012-12-07  7:50 ` Wanlong Gao
  3 siblings, 0 replies; 10+ messages in thread
From: Wanlong Gao @ 2012-12-07  7:50 UTC (permalink / raw)
  To: Peng Haitao; +Cc: ltp-list

On 12/04/2012 03:21 PM, Peng Haitao wrote:
> Add four functions of controlling daemon:
>   - start_daemon
>   - stop_daemon
>   - status_daemon
>   - restart_daemon
> 
> Signed-off-by: Peng Haitao <penght@cn.fujitsu.com>

Applied, thank you.

Wanlong Gao


------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 2/4] runnetnstest.sh: fix a fail of vsftpd is disabled
  2012-12-04  7:21 ` [LTP] [PATCH 2/4] runnetnstest.sh: fix a fail of vsftpd is disabled Peng Haitao
@ 2012-12-07  7:50   ` Wanlong Gao
  0 siblings, 0 replies; 10+ messages in thread
From: Wanlong Gao @ 2012-12-07  7:50 UTC (permalink / raw)
  To: Peng Haitao; +Cc: ltp-list

On 12/04/2012 03:21 PM, Peng Haitao wrote:
> When vsftpd is disabled, runnetnstest.sh should start vsftpd first.
> 
> Signed-off-by: Peng Haitao <penght@cn.fujitsu.com>

Applied, thank you.

Wanlong Gao


------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2012-12-07  7:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-04  7:21 [LTP] [PATCH 1/4] cmdlib.sh: Add four functions of controlling daemon Peng Haitao
2012-12-04  7:21 ` [LTP] [PATCH 2/4] runnetnstest.sh: fix a fail of vsftpd is disabled Peng Haitao
2012-12-07  7:50   ` Wanlong Gao
2012-12-04  7:21 ` [LTP] [PATCH 3/4] at_allow01: Use lib to restart atd service Peng Haitao
2012-12-04  7:39   ` Caspar Zhang
2012-12-04  9:17     ` Peng Haitao
2012-12-05  4:40       ` Caspar Zhang
2012-12-06 14:24     ` chrubis
2012-12-04  7:21 ` [LTP] [PATCH 4/4] at_deny01: " Peng Haitao
2012-12-07  7:50 ` [LTP] [PATCH 1/4] cmdlib.sh: Add four functions of controlling daemon Wanlong Gao

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