Skip to contentSkip to conversation

daemonlib.sh: Don't assume service support

PATCH In review Carlos Hernandez 2 participants 2 messages Mar 30, 2015 – Apr 23, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 daemonlib.sh: Don't assume service support

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.

---
 testcases/lib/daemonlib.sh | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
testcases/lib/daemonlib.sh +12 -4
index b924e17..3d67125 100644
@@ -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
 }
Signature · 13 lines
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw

Hi!

Quoted 4 lines

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.

Pushed, thanks.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list