[Backgroundrb-devel] PID File Overwritten on Failed Start

Ian Lesperance ian.lesperance at gmail.com
Thu Jul 3 16:33:11 EDT 2008

I have monitoring in place for BackgrounDRb to ensure that it stays
up, but I've been getting some false alarms lately.  I've realized
that it has to do with the way BackrounDRb daemonizes.  If you attempt
to start BackgrounDRb while it's already running, it's going to (1)
write its new PID to the file then (2) fail with Errno::EADDRINUSE
upon attempting to establish a socket connection.

Because of a small deployment race condition, sometimes my monitoring
software attempts to start BackgrounDRb along with my actual
deployment scripts.  This causes an invalid PID to get written to the
file.  Since my monitoring software uses this PID file to determine
the status of BackgrounDRb, it keeps sending out false outage alerts
and attempting (and failing) to restart BackgrounDRb.

Now, one quick and simple solution to this is to store the old PID in
a variable, rescue the Errno::EADDRINUSE, and restore the old PID.
I've already written a patch that does just that.

However, is there any reason it should even attempt to start in the
presence of an existing process?  If not, then I could just use
something like Process.getpgid() to check if the old process still
exists and abort the start before.



More information about the Backgroundrb-devel mailing list