Add four functions of controlling daemon: - start_daemon - stop_daemon - status_daemon - restart_daemon
Signed-off-by: Peng Haitao <[email protected]> --- 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 [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
