Simon icon Simon
Flexible server monitoring

Application/Process running

I would like to have a test to see if a background process is running. Because it's a background process, the "Application" service doesn't work. I have tried the "Is App Running?" script from the Extras page, but it does not seem to be reliable. It will sometimes report failures even if the process is running. For example, I used it to test to see if Simon was running, and that test fails periodically, and I get notified! So clearly Simon was running the entire time, i.e. there was a false failure. I'm guessing it could be related to the Applescript test not being right all the time. Or, it *could* be that two regularly running osascript things on the machine collide. Perhaps only one can be running at once? (Doesn't seem likely, and doesn't seem likely that two would collide, but I can't think of any other reason.)

I also tried writing a shell script test (run 'ps -auxww', grep for the process name, and do a 'wc -l' to see if it is running) but was not successful with that.

Any ideas? Any other suggestions for checking to see if a background app/process is running?


David Sinclair's picture

Re: Application/Process running

I think you're on the right track. I'd recommend using a shell script service.

Check out the "Web Server Running" script, which looks for the httpd background process. It uses:

ps ax | grep -v grep | grep httpd

no luck w/ "Web Server Running" script so far

Thanks for you help, but no luck so far.

My script has

ps ax | grep -v grep | grep {Application}

If I set the Default Value for Application (a Custom Variable) to "httpd" it works great. If I set it to IndigoServer (the process I'm really interested in) it fails. And yet both are running. I ran the two scenarios at the command line, and the only difference I can see is that

ps ax | grep -v grep | grep httpd

return several lines (several httpd processes) while

ps ax | grep -v grep | grep IndigoServer

only returns one line (only one IndigoServer process). I tried it w/ several names of single-instance processes, and they failed, while tests with multiple-instance processes (e.g., qrunner, httpd) succeeded.

Any ideas?

Thanks again.

David Sinclair's picture

Re: no luck w/ "Web Server Running" script so far

Hmm... I wish I was more familiar with unix; this seems like an obscure unixy thing.

Since the unix commands seem to output the correct thing (one line if it's running, none if not), the key must be the result code. What result appears if you try a Preview of the script in both cases?

If that doesn't help, you could use Smart Change Detection: type "IndigoServer" (without the quotes in the Start text box, and leave the End text box empty. That will result in success if it is present, and a failure if it's missing. Not quite as elegant as doing it in the script, but it'd work if we can't figure out the right script config.

missing output line?

The unix commands produce the expected output when run at the command line in a Terminal session, but not from within Simon. It's very strange. I made a simple Script service using the C shell (/bin/csh). It has one simple piped command:

ps -ax | grep Simon

When I run this from within a Terminal window (using the C shell) I get three lines as follows:

[server:~] welch% ps -ax | grep Simon
  402  ??  S    371:27.70 /Applications/ -psn_0_2228225
  411  ??  Ss     0:00.62 /Applications/ -pidToWat
11722  p1  UV+    0:00.00 grep Simon
[server:~] welch%

But when I do a Preview from within the Service editing window, I get inconsistent results. Some times it runs for a while, saying "Loading..." with the spinning fan icon, until I cancel it. Some times it "succeeds" (returns a 0), but only prints two line of output as follows (for example):

  402  ??  S    371:56.78 /Applications/ -psn_0_2
  411  ??  Ss     0:00.62 /Applications/

Notice the "grep" process is missing. Other times it "succeeds" (returns a 0), and prints the same three lines as in the Terminal window.

With the preview window open I can click "Check Now" repeatedly, and I get the endless load, three lines, or two lines. I can't see a pattern.

It's almost (it seems) as if Simon is some times losing one line of the result. This might explain why a single-instance process might be missed some times.


David Sinclair's picture

Re: missing output line?

Hi, sorry for the little delay in replying. I've been investigating this issue.

I can confirm that occasionally it seems to drop some data from the end. Or more precisely, that data is never received by Simon, in those cases. I haven't figured out why yet, but am continuing to investigate.

Thanks for bringing this to my attention.

OK, thanks!

Glad at least that you see it too. I'd be happy to test something if it would help.

Try using the w and c

Try using the w and c options with ps.

ps -awcx |grep Simon

One test succeeds, another fails... but they're the same test!!!

I've set up two tests both using the "Is Process Running" service. The first checks for the process "FM Web Publishing" and that works, succeeds every time. The second checks for the process "fmserverd" and that fails every time! Yet both tests are setup exactly -- and I mean EXACTLY -- the same way. Both use the same service.

Even if I pause both indefinitely and then manually run the "fmserverd" check by clicking Check Now it fails. But the process is running. The same unix command run in Terminal returns a positive result.

What gives?

Found a workaround

I duplicated the "Web Server Running" service and instead had it check for fmserverd instead of httpd. That works. So to be on the safe side I also created a separate service for FM Web Publishing that executes the same check. Seems to be happy now.