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
# 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
# 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
# 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.
# 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.
# 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