Restarting Unicorn with Usr2 Doesn't Seem to Reload Production.Rb Settings

Restarting Unicorn with USR2 doesn't seem to reload production.rb settings

My guess is that your unicorns are being restarted in the old production directory rather than the new production directory -- in other words, if your working directory in unicorn.rb is <capistrano_directory>/current, you need to make sure the symlink happens before you attempt to restart the unicorns.

This would explain why stopping and starting them manually works: you're doing that post-deploy, presumably, which causes them to start in the correct directory.

When in your deploy process are you restarting the unicorns? You should make sure the USR2 signal is being sent after the new release directory is symlinked as current.

If this doesn't help, please gist your unicorn.rb and deploy.rb; it'll make it a lot easier to debug this problem.

Unicorn zero downtime does not work

Solved problem by following changes:

# config/unicorn.rb
Unicorn::HttpServer::START_CTX[0] = "#{rails_root}/bin/unicorn"

before_exec do |server|
# Ensure unicorn picks up our newest Gemfile
ENV['BUNDLE_GEMFILE'] = "<%= current_path %>/Gemfile"
end

# unicorn.cap
def run_unicorn
within current_path do
# change execute :unicorn, instead of :unicorn_rails
execute :unicorn, "-c #{current_path}/config/unicorn.rb -D -E #{fetch(:rails_env)}"
end
end

See also: http://unicorn.bogomips.org/Sandbox.html

Unicorn restarting in old release directory

Had a reference to "Rails.root" in one of my Rake tasks which was causing the symlink to resolve. Replaced that with a hardcoded reference to the shared directory and it worked.

Unicorn failing to spawn workers on USR2 signal

Well, turns out you have to run in daemonized mode (-D) if you want to be able to do zero downtime deployment. I changed a few things in my upstart script and now it works fine:

setuid username
pre-start exec unicorn_rails -E production -c /path/to/app/config/unicorn.rb -D
post-stop exec kill cat `/path/to/app/tmp/pids/unicorn.pid`
respawn

Unicorn downs for few seconds after USR2 and QUIT signals (Should not)

This is an expected behavior:

Supervisord requires the unicorn process to not daemonize. Also sending SIGUSR2 to unicorn causes the old master to die. Since supervisord watches the old master this will cause it to consider the application as exited, even tho it's running with a new process id. Finally Supervisor will try to restart the application, and fail to do so because all sockets are in use by the new unicorn master.

Solution:

  1. Either use -D option and start your unicorn rails app yourself without systemd/supervisord. Then USR2 will work.
  2. Or use unicornherder for wrapper. This will do the job for you. No downtime.

See link: Unicorn + Systemd/Supervisord & Zero Downtime = unicornherder



Related Topics



Leave a reply



Submit