Refactor and get exec + FD inheritance working
commit101fb9ad1372e97ddf998c7fd677e352719c90e8
authorEric Wong <normalperson@yhbt.net>
Mon, 9 Feb 2009 22:26:34 +0000 (9 14:26 -0800)
committerEric Wong <normalperson@yhbt.net>
Tue, 10 Feb 2009 03:52:20 +0000 (9 19:52 -0800)
tree354b0cd16fa1ca81b2f24b843e7bedf2f1eeef97
parent0b9dac5de7ecf8111dd3d9fa621edc759c9c47e3
Refactor and get exec + FD inheritance working

Along with worker process management.  This is nginx-style
inplace upgrading (I don't know of another web server that does
this).  Basically we can preserve our opened listen sockets
across entire executable upgrades.

Signals:

  USR2 - Sending USR2 to the master unicorn process will cause
  it to exec a new master and keep the original workers running.
  This is useful to validate that the new code changes took place
  are valid and don't immediately die.  Once the changes are
  validated (manually), you may send QUIT to the original
  master process to have it gracefully exit.

  HUP - Sending this to the master will make it immediately exec
  a new binary and cause the old workers to gracefully exit.
  Use this if you're certain the latest changes to Unicorn (and
  your app) are ready and don't need validating.

Unlike nginx, re-execing a new binary will pick up any and all
configuration changes.  However listener sockets cannot be
removed when exec-ing; only added (for now).

I apologize for making such a big change in one commit, but once
I got the ability to replace the entire codebase while preserving
connections, it was too tempting to continue working.

So I wrote a large chunk of this while hitting
the unicorn-hello-world app with the following loop:

   while curl -vSsfN http://0:8080; do date +%N; done

_Zero_ requests lost across multiple restarts.
bin/unicorn [new file with mode: 0755]
bin/unicorn-hello-world [new file with mode: 0755]
lib/unicorn.rb
lib/unicorn/http_request.rb
lib/unicorn/http_response.rb
lib/unicorn/socket.rb