How to automate the restarting of Unicorn?

Devin Ben-Hur dbenhur at whitepages.com
Mon Oct 10 02:04:13 EDT 2011


On 10/09/2011 04:31 PM, Alex Sharp wrote:
> On Friday, October 7, 2011 at 8:20 PM, Pai-Hung Chen wrote:
>> My question is: By the time the "before_exec" hook is executed, is it
>> guaranteed that unicorn.pid.oldbin 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: 
https://github.com/defunkt/unicorn/blob/master/lib/unicorn/http_server.rb

Unicorn::HttpServer#pid=(path) setter writes the pid file (lines 179-206).

before_exec is called on line 439 within a fork block in 
Unicorn::HttpServer#reexec (this is the only call to before_exec in the 
code)

prior to that, self.pid= is called passing oldpid whose value is 
"#{pid}.oldbin" (lines 398-401).

[ line numbers may change if you're not looking at commit c7ba76a21c ]


More information about the mongrel-unicorn mailing list