Restart Unicorn Question (capistrano)

I have the 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 that will not work. I mean that the command is executed (it asks for a password and does not give any errors), but all changes in the configuration files are still ignored (for example, the number of work processes or database settings).

+6
source share
3 answers

Perhaps this is because of how restarting the unicorn. Not every worker reboots immediately. This is done in order to have zero downtime and to lose any requests. If you want to accurately see your changes, try stopping and then launching the application. I had to do this several times. Of course, you may lose some query.

The following tasks are what I use to restart, stop, and start 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.

Perhaps this article is of interest.

+18
source

see here my child ~ Restarting the 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)

Since the error unlocking the soft link of the unicorn and linux: soft link may not work well.

+1
source

You should let capistrano-unicorn try what I am currently using with the default hooks mentioned below.

Customization

Add the library to your Gemfile :

ruby group :development do gem 'capistrano-unicorn', :require => false end

And load it into your deployment script config/deploy.rb :

ruby require 'capistrano-unicorn'

Add the unicorn reboot launch task:

ruby after 'deploy:restart', 'unicorn:reload' # app IS NOT preloaded after 'deploy:restart', 'unicorn:restart' # app preloaded after 'deploy:restart', 'unicorn:duplicate' # before_fork hook implemented (zero downtime deployments)

0
source

Source: https://habr.com/ru/post/906950/


All Articles