[Pm-utils] [PATCH] use service unconditionally

Stefan Seyfried seife at suse.de
Mon Mar 12 00:25:53 PDT 2007


On Sat, Mar 10, 2007 at 09:11:14PM +0100, Tim Dijkstra wrote:
> On Sat, 10 Mar 2007 16:49:04 +0200
> "S.Çağlar Onur" <caglar at pardus.org.tr> wrote:
> > * Ignore all threads/patches/comments so distros/people can fork/alternate 
> > pm-utils which works just for them happily

Oh, why has this already crossed my mind, too? ;-)

> It appears that is inevitable that we introduce distro specific
> functions here, because you do not appear to have /etc/init.d and we
> don't have service.

how about (untested!):

Index: pm/functions
===================================================================
RCS file: /cvs/pm-utils/pm-utils/pm/functions,v
retrieving revision 1.36
diff -u -p -r1.36 functions
--- pm/functions	6 Mar 2007 19:59:05 -0000	1.36
+++ pm/functions	12 Mar 2007 07:22:41 -0000
@@ -222,20 +222,33 @@ modreload()
 	fi
 }
 
+myservice()
+{
+	type service >/dev/null 2>&1
+	if [ $? = 0 ]; then
+		service "$@"
+	elif [ -x "/etc/init.d/$1" ]; then
+		"/etc/init.d/$@"
+	else
+		echo "neither 'service' nor '/etc/init.d/$1' init-script found." >&2
+		echo "installation or configuration problem?" >&2
+		echo "command was: 'myservice $@'" >&2
+	fi
+}
+
 stopservice()
 {
-	service "$1" status 2>/dev/null | grep -c -q running
-	if [ "$?" == "0" -a -x "/etc/init.d/$1" ]; then
+	myservice "$1" status 2>/dev/null | grep -c -q running
+	if [ "$?" == "0" ]; then
 		echo "export ${1}_SERVICE_ACTIVATE=yes" >> /var/run/pm-suspend
-		"/etc/init.d/$1" stop 2>&1
+		myservice "$1" stop 2>&1
 	fi
 }
 
 restartservice()
 {
-	if [ "x$(eval echo \$${1}_SERVICE_ACTIVATE)" == "xyes" \
-			-a -x "/etc/init.d/$1" ]; then
-		"/etc/init.d/$1" start 2>&1
+	if [ "x$(eval echo \$${1}_SERVICE_ACTIVATE)" == "xyes" ]; then
+		myservice "$1" start 2>&1
 	fi
 }
 
-- 
Stefan Seyfried

"Any ideas, John?"
"Well, surrounding them's out." 


More information about the Pm-utils mailing list