lib/caploy/templates/unicorn/unicorn.rb.erb in caploy-0.1.3 vs lib/caploy/templates/unicorn/unicorn.rb.erb in caploy-0.1.4

- old
+ new

@@ -13,17 +13,21 @@ # Disconnect since the database connection will not carry over if defined? ActiveRecord::Base ActiveRecord::Base.connection.disconnect! end - # Quit the old unicorn process + # This allows a new master process to incrementally + # phase out the old master process with SIGTTOU to avoid a + # thundering herd (especially in the "preload_app false" case) + # when doing a transparent upgrade. The last worker spawned + # will then kill off the old master process with a SIGQUIT. old_pid = "#{server.config[:pid]}.oldbin" - if File.exists?(old_pid) && server.pid != old_pid - begin - Process.kill("QUIT", File.read(old_pid).to_i) - rescue Errno::ENOENT, Errno::ESRCH - # someone else did our job for us - end + if File.exists?(old_pid) && old_pid != server.pid + begin + sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU + Process.kill(sig, File.read(old_pid).to_i) + rescue Errno::ENOENT, Errno::ESRCH + end end end after_fork do |server, worker| # Start up the database connection again in the worker \ No newline at end of file