How to trap USR2 for custom ussage ?

Iñaki Baz Castillo ibc at
Wed Dec 23 09:29:11 EST 2009

Hi, I've modified bin/unicorn to start a DRb server before last lines:

  Unicorn::Launcher.daemonize! if daemonize, options)

DRb server listens in port 5555. When I send a USR2 signal to unicorn master 
process I get an error because DRb is started again so:

  /usr/local/lib/ruby1.9/1.9.1/drb/drb.rb:861:in `initialize': Address already
  in use - bind(2) (Errno::EADDRINUSE)

The only solution I can imagine is to trap USR2 signal:

  trap("USR2") { ::DRb.stop_service }
  Unicorn::Launcher.daemonize! if daemonize, options)

Unfortunatelly it doesn't work because Unicorn overrides the 'trap' call so I 
don't get the USR2 signal.

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" 

Does it make sense?

Thanks a lot.

Iñaki Baz Castillo <ibc at>

More information about the mongrel-unicorn mailing list