How to trap USR2 for custom ussage ?

Iñaki Baz Castillo ibc at
Thu Dec 24 04:40:25 EST 2009

El Miércoles, 23 de Diciembre de 2009, Eric Wong escribió:

> First off I really don't think you need to be using DRb for this or
> (generally) sticking things into the master process that don't belong
> there.

The problem is: how to start a server (which binds in a TCP port) in just one 
worker? humm, would the following make sense?:

  after_fork do |server, worker|
    # Start DRb server just in worker[0]
    if == 0
      ... start DRb server ...

But it would also fail upon receipt of USR2 as there would be two instances of 
the DRb server trying to bind on same port...

> > Is there any way to achive this?
> > I could imagine a new config option "on_usr2" (or "before_reexec") so the
> > passsed block would be executed upon receipt of USR2 (before the real
> > "reexec" method).
> >
> > Does it make sense?
> There's already a similar before_exec hook documented in
> But it is called after forking, so the listener will be shared.

Hummm, perhaps I could use the above code plus:

  before_exec do |server|
    .... stop DRb server ...

In this way the DRb server is stopped before exec and started in the new 
Just a problem, how to access to existing/old worker[0] from "before_exec" in 
order to stop the DRb server?

> But again, you don't need to use DRb for this.

As I've said in other thread I want DRb to get some info related to the 
application. A DRb client console could be used to check application 
database(s) connection and so.
What would you suggest for this rather than DRb server?

Again thanks a lot for your help.

Iñaki Baz Castillo <ibc at>

More information about the mongrel-unicorn mailing list