How to automate the restarting of Unicorn?

Eric Wong normalperson at
Mon Oct 10 17:27:41 EDT 2011

Pai-Hung Chen <paihungchen at> wrote:
> > On 10/10/2011 08:04 AM, Devin Ben-Hur wrote:
> > >> My question is: By the time the "before_exec" hook is executed, is it
> > >> guaranteed that ahas lready created (otherwise we
> > >> have a racing condition here)? Or is there a better way to achieve
> > >> what I want?
> > > I'm not 100% positive, but about 98% -- yes, you can count on the fact that
> the *.oldbin file will exist on
> > > disk before the before_exec block is executed. Eric can confirm this, but
> I've never had a problem with it...
> > No need to rely on authority, just read the source: 
> >

100% correct, source code never lies.

> Thanks for the pointer. The current source code clearly shows before_exec is
> called after the .oldbin file is created. I'd like to know if this is considered
> an "invariant" going forward.

Yes, there's no way to safely handle the pid file otherwise because of
race conditions you mentioned.  The oldbin pid file must exist because
the new process (which calls before_exec) can clobber the regular pid
file once fork is called.

> Could someone in the "authority" help?

Fwiw, I'm only reluctantly an "authority".  I'm against the notion of
authority.  I am and forever will be nobody :)

More information about the mongrel-unicorn mailing list