Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have ruby daemons running. Once in a while we'll accidentally start up a second instance of it, which causes race conditions.

Can I use Monit to detect if multiple instances of 'my_ruby_daemon' is running? And if so kill the extra instance?

share|improve this question
Good question... I'll look into it. – ewwhite Nov 7 '12 at 18:08

I don't know if you can do this with monit, but it strikes me as the Wrong Solution which may bring up its own problems (especially if Bad Things happen if you kill the "wrong" daemon (?)).

The Right Solution is to have your daemon create and check a lock (PID files work great for this -- if exists and the PID in it is alive refuse to start the daemon).
There are several ruby lockfile gems/libraries/etc available (like this one).
If modifying the daemon is out of the question almost every Unix system comes with the lockfile command or something similar -- wrap the daemon in a shell script that creates/checks the lock before attempting to start.

It helps if you put the lock file somewhere that gets cleared on reboot (/tmp, /var/run, etc.) so that if your system crashes the daemon will restart when its init script runs.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.