Is there a trick to get the status of a service on a MAC?


For some reason, I cannot seem to figure out how to get the status of a service on a Mac. (10.9) For Windows and Linux, I just need to use state of service "service name", but this does not work on Mac. (Singular expression refers to nonexistent object) It looks like exists service "service name" also only returns false, even when I know the service is installed and running. (For example, the process for BESAgent…I know that “service” and “process” are not really the same thing, but I figured that since it works on Linux, that there may be similar functionality for Macs.)

Any ideas? I know that I can write a script to get back this information, but I need a way to get this information in a relevance block for an analysis property.

I will need to get this information for ~20 different versions of operating systems, but the two I am testing right now are:
Linux - CentOS 5.11 with BES Agent
Mac - OS X 10.9 with BES Agent

What are you trying to accomplish?

“The service Inspectors provide access to all services configured on Windows NT, 2K and XP systems. On a non-Windows system, expressions using these objects will fail gracefully instead of generating an error.”

I am trying to get the status of various agents on various platforms. I know that in the past, the “state of service” and “exists service” only worked on Windows, but now it always works on Linux system.

I can do all of this in scripts, but I don’t know of a way to run the scripts in a relevance statement.

In one analysis, I am checking on the existence of 9 services and then reporting the status of them if they exist. I have it working for Windows and Linux, just not for Mac yet. I imagine that others have run into similar issues in the past, but I have not been able to find any good examples of how to accomplish this for Mac yet.

The only way I know would be to do an actionscript and use launchctl directly

You could do

launchctl list

And redirect to a file and then you can parse the resulting file to get the services you need.

We do need to extend the service concept on OSX for sure.

1 Like

Ok, thanks for the help. It looks like I will need to write my own process, to monitor the other processes, to then generate the report on if the processes are installed and running correctly.

1 Like

It doesn’t look like there has been any update with natively checking for the status of a service on Mac OS X:
Inspectors - Service

Is outputting “launchctl list” to a file and then reading that still the only/best way to do this?

1 Like

You can look at the launchd items defined in files / plists directly without running launchctl list and compare the results to launchctl list

files of (folders "LaunchAgents" of it; folders "LaunchDaemons" of it) of folders "Library" of (folders "/"; folders "/System")

Then to get the label inside the plist definition:

strings "Label" of dictionaries of files of (folders "LaunchAgents" of it; folders "LaunchDaemons" of it) of folders "Library" of (folders "/"; folders "/System")

You could also search for user launch agents as well, though this could take a while if there are a large number of users:

strings "Label" of dictionaries of files of (folders "LaunchAgents" of it; folders "LaunchDaemons" of it) of folders "Library" of (folders "/"; folders "/System"; folders of folders "/Users")

Ideally there would be an inspector added for this.