私が設定した方法は、ユニコーンサーバーを再起動するときのようなものを使用することです。ユニコーンサーバーの構成では、次のようなものを使用します( http://unicorn.bogomips.org/examples/unicorn.conf.rbkill -USR2 $(cat /path/to/unicorn.pid)
に基づく):
# feel free to point this anywhere accessible on the filesystem
pid "#{shared_path}/pids/unicorn.pid"
before_fork do |server, worker|
# the following is highly recomended for Rails + "preload_app true"
# as there's no need for the master process to hold a connection
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
# 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 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
これにより、新しいワーカーが起動し、古いワーカーのスイッチが徐々にオフになります。