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

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