Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart Unicorn issue (capistrano)

I've got following settings in deploy.rb to restart my server:

namespace :deploy do
  task :restart do
    run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -USR2     \`cat #{unicorn_pid}\`; else cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -    E #{rails_env} -D; fi"
  end
end

but it doesn't work. I mean that command executes (it asks me the password and gives no errors), but all changes in config files are still ignored (i.e. number of worker processes or database settings).

like image 810
leitasat Avatar asked Jan 26 '12 15:01

leitasat


2 Answers

Maybe this is because of the way unicorn restarts. Not every worker is restarted immediately. This is to make it possible to have zero downtime and loose no requests. If you want to see your changes for sure, try to stop and then start your application instead. I have had to do this some times. Of course you will potentially loose some request.

The following tasks is what I use for restarting, stopping, and starting my unicorn server.

desc "Zero-downtime restart of Unicorn"
task :restart, :except => { :no_release => true } do
  run "kill -s USR2 `cat #{shared_path}/pids/unicorn.pid`"
end

desc "Start unicorn"
task :start, :except => { :no_release => true } do
  run "cd #{current_path} ; bundle exec unicorn_rails -c config/unicorn.rb -D -E production"
end

desc "Stop unicorn"
task :stop, :except => { :no_release => true } do
  run "kill -s QUIT `cat #{shared_path}/pids/unicorn.pid`"
end

Hope this helps you.

Maybe this article is of interest.

like image 90
Godisemo Avatar answered Oct 15 '22 16:10

Godisemo


see here my baby~ Restarting Unicorn with USR2 doesn't seem to reload production.rb settings

Keep in mind that: your working directory in unicorn.rb should be : /your/cap/directory/current

NOT be: File.expand_path("../..", FILE)

Because the unicorn and linux soft link forking error: soft link can not work well.

like image 31
fantaxy025025 Avatar answered Oct 15 '22 14:10

fantaxy025025