Some systems (i.e. embedded distributions) do not support service.
Instead /etc/init.d/ scripts are called directly. So use service if
available otherwise try to start daemon by calling /etc/init.d/
script.

Signed-off-by: Carlos Hernandez <c...@ti.com>
---
 testcases/lib/daemonlib.sh | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/testcases/lib/daemonlib.sh b/testcases/lib/daemonlib.sh
index b924e17..3d67125 100644
--- a/testcases/lib/daemonlib.sh
+++ b/testcases/lib/daemonlib.sh
@@ -48,8 +48,10 @@ start_daemon()
 {
        if [ $HAVE_SYSTEMCTL -eq 1 ]; then
                systemctl start $1.service > /dev/null 2>&1
-       else
+       elif command -v service &> /dev/null; then
                service $1 start > /dev/null 2>&1
+       else
+               /etc/init.d/$1 start > /dev/null 2>&1
        fi
 }
 
@@ -57,8 +59,10 @@ stop_daemon()
 {
        if [ $HAVE_SYSTEMCTL -eq 1 ]; then
                systemctl stop $1.service > /dev/null 2>&1
-       else
+       elif command -v service &> /dev/null; then
                service $1 stop > /dev/null 2>&1
+       else
+               /etc/init.d/$1 stop > /dev/null 2>&1
        fi
 }
 
@@ -66,8 +70,10 @@ status_daemon()
 {
        if [ $HAVE_SYSTEMCTL -eq 1 ]; then
                systemctl status $1.service > /dev/null 2>&1
-       else
+       elif command -v service &> /dev/null; then
                service $1 status > /dev/null 2>&1
+       else
+               /etc/init.d/$1 status > /dev/null 2>&1
        fi
 }
 
@@ -75,7 +81,9 @@ restart_daemon()
 {
        if [ $HAVE_SYSTEMCTL -eq 1 ]; then
                systemctl restart $1.service > /dev/null 2>&1
-       else
+       elif command -v service &> /dev/null; then
                service $1 restart > /dev/null 2>&1
+       else
+               /etc/init.d/$1 restart > /dev/null 2>&1
        fi
 }
-- 
1.9.1


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to