Determining service existence

I'm currently writing a module for Cfengine to enable and disable services via SMF. However, a particular service isn't necessarily installed on every system (e.g. we don't install CDE on servers so services like "cde-login" won't exist). Is there a recommended way to test for the existence of a service prior to manipulating it?

I'm currently using "svcprop -q <service>" and testing the exit status, but I'm not sure this is robust since a non-zero exit code could occur on other fatal errors.

Cheers,

Ade

[545 byte] By [aderixona] at [2007-11-27 2:09:28]
# 1

There's actually a difference between a "service" existing (like svc:/network/smtp) and a "service instance" existing (like svc:/network/smtp:sendmail).

You can see all service instances with 'svcs -a'.

'svccfg list' will show all services (but not instances).

--

Darren

Darren_Dunhama at 2007-7-12 1:59:55 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 2

Thanks, but what I actually need is the ability in a script to ask "does service instance foo exist?" and get a yes or no answer, preferably via a robust exit code. svcprop would appear to give me yes or no/error. I'd rather do this without receiving unwanted messages on stderr ("pattern 'foo' doesn't match any instances") or grepping the output of a list command.

Ade

aderixona at 2007-7-12 1:59:55 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 3

I wasn't sure if you were interested in non-instanced services or not (svcs wouldn't be appropriate if so).

I would generally use 'svcs <service instance>' myself, since that operates on service instances.

You might want to put in an RFE for a 'quiet' mode that doesn't display data, but only sets the exit code.

--

Darren

Darren_Dunhama at 2007-7-12 1:59:55 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 4

svcprop -q is the recommended way. Unfortunately it's not precise,

as you point out.

You can file an RFE for a more precise svcprop at bugs.opensolaris.org,

but it would probably be easier to just test for the service manifest file

which contains the service, and assume that it was imported.

David_Bustosa at 2007-7-12 1:59:56 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 5
Testing for a manifest seems wrong to me. Services and manifest may often be disconnected. Some services may not even have a manifest. Or it may have a manifest in a non-standard location.-- Darren
Darren_Dunhama at 2007-7-12 1:59:56 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 6
I wouldn't recommend it as a generic method. But for a Sun-deliveredservice, it's a pretty safe bet.
David_Bustosa at 2007-7-12 1:59:56 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 7
How about if a service is deleted. The auto-import won't bring it back in, will it? Someone recently mentioned VCS documentation that deletes NFS services (but leaves the manifests in place).-- Darren
Darren_Dunhama at 2007-7-12 1:59:56 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 8
The current implementation will reimport the manifest if it changes,which will bring the service back. I think this is a bug, and I think I canfix it with the Enhanced SMF Profiles project.
David_Bustosa at 2007-7-12 1:59:56 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 9

Thanks for the replies. On further thought, I suspect I'm worrying unnecessarily on this point; it's pretty much the same behaviour as egrep -s. And if svcprop fails for any other reason beyond the service not existing, chances are I don't want to try manipulating that service anyway so I might as well assume it's not present.

Cheers,

Ade

aderixona at 2007-7-12 1:59:56 > top of Java-index,Solaris Operating System,Solaris 10 Features...