Anyone have any tips for using Capistrano with unicorn?
I''m following what GitHub did (http://github.com/blog/517-unicorn) ,
and for some reason, my old master isn''t dying correctly. If I `pkill
-9 unicorn_rails && unicorn_rails` the new code shows up. I''m
thinking
the problem may be with how capistrano uses the ''current''
directory as
a symlink.
That config''s before_fork seems to make sense to me; I might just be
doing something stupid.
Here''s my config, for reference:
# Use at least one worker per core if you''re on a dedicated server,
# more will usually help for _short_ waits on databases/caches.
worker_processes 16
working_directory "/home/git/site/current" # available in 0.94.0+
# listen on both a Unix domain socket and a TCP port,
# we use a shorter backlog for quicker failover when busy
listen "/tmp/.sock", :backlog => 64
listen 8080, :tcp_nopush => true
timeout 600
pid "/var/run/unicorn.pid"
# some applications/frameworks log to stderr or stdout, so prevent
# them from going to /dev/null when daemonized here:
stderr_path "/var/log/unicorn.stderr.log"
stdout_path "/var/log/unicorn.stdout.log"
# combine REE with "preload_app true" for memory savings
# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
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!
old_pid = RAILS_ROOT + ''/tmp/pids/unicorn.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
end
end
after_fork do |server, worker|
# the following is *required* for Rails + "preload_app true",
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
I am using ree, so preload_app should be in effect.
Thanks in advance.