From: Ian Leitch <port001@gmail.com>
To: mongrel-unicorn@rubyforge.org
Subject: RAILS_ROOT and USR2 restarts
Date: Mon, 26 Oct 2009 11:04:56 -0400 [thread overview]
Message-ID: <d7a220010910260804n4f403vb1cdc526db6d3aea@mail.gmail.com> (raw)
Hi,
I've just started using Unicorn in production behind Nginx with a
Rails app, for the most part its been a smooth transition apart from
this one issue.
When I do an in place restart (USR2), the restart process works but
the workers load my old Rails release, not the new one. I'm guessing
that because the master process is currently in the old release
directory, when I signal USR2 it's just reloading inside the current
directory. I'm deploying with Capistrano, so app/current is a symlink
to a specific release. I've tried changing to the new release
directory in before_work but that made no difference. Is there a
callback that fires before the master preloads the app?
worker_processes 6
preload_app true
timeout 60
listen "/tmp/unicorn.production.sock"
pid "/tmp/unicorn.production.pid"
before_fork do |server, worker|
Dir.chdir("/var/www/apps/systino_production/current")
old_pid = "/tmp/unicorn.#{RAILS_ENV}.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|
ActiveRecord::Base.establish_connection
end
I also have a little launcher script (I'm using Solaris - SMF doesn't
let me provide a custom restart routine, so I have to bypass it and
use this script):
#!/usr/bin/ruby
$rails_env = ARGV[0]
$pid_file = "/tmp/unicorn.#{$rails_env}.pid"
def restart(pid)
system("kill -USR2 #{pid}")
end
def start
system("/opt/local/bin/unicorn_rails -c config/unicorn.rb -E
#{$rails_env} -D")
end
if File.exists?($pid_file)
pid = File.read($pid_file).strip.to_i
begin
Process.kill(0, pid)
rescue Errno::ESRCH
# Not running
start
else
restart(pid)
end
else
start
end
At the end of the deploy I execute:
task :restart_unicorn do
run "cd #{current_path}; ruby config/unicorn_launcher.rb #{rails_env}"
end
_______________________________________________
mongrel-unicorn mailing list
mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
next reply other threads:[~2009-10-26 15:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-26 15:04 Ian Leitch [this message]
2009-10-26 16:01 ` RAILS_ROOT and USR2 restarts Eric Wong
2009-10-26 16:13 ` Ian Leitch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/unicorn/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d7a220010910260804n4f403vb1cdc526db6d3aea@mail.gmail.com \
--to=port001@gmail.com \
--cc=mongrel-unicorn@rubyforge.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/unicorn.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).