简体   繁体   English

重启Unicorn问题(capistrano)

[英]Restart Unicorn issue (capistrano)

I've got following settings in deploy.rb to restart my server: 我在deploy.rb中有以下设置来重启我的服务器:

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 (ie number of worker processes or database settings). 我的意思是该命令执行(它询问密码并且没有错误),但是配置文件中的所有更改仍然被忽略(即工作进程数或数据库设置)。

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. 以下任务是我用于重启,停止和启动我的unicorn服务器的任务。

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. 也许这篇文章很有意思。

see here my baby~ Restarting Unicorn with USR2 doesn't seem to reload production.rb settings 看到我的宝贝〜 用USR2重启Unicorn似乎没有重新加载production.rb设置

Keep in mind that: your working directory in unicorn.rb should be : /your/cap/directory/current 请记住:unicorn.rb中的工作目录应为:/ your / cap / directory / current

NOT be: File.expand_path("../..", FILE) 不是:File.expand_path(“../ ..”,FILE)

Because the unicorn and linux soft link forking error: soft link can not work well. 因为独角兽和linux软链接分叉错误:软链接无法正常工作。

You should give capistrano-unicorn a try, that's what I currently use with the default hooks mentioned below. 你应该试试capistrano-unicorn ,这就是我目前使用下面提到的默认钩子。

Setup 设定

Add the library to your Gemfile : 将库添加到Gemfile

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

And load it into your deployment script config/deploy.rb : 并将其加载到部署脚本config/deploy.rb

ruby require 'capistrano-unicorn'

Add unicorn restart task hook: 添加unicorn restart任务钩子:

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM