重启 Unicorn 问题 (capistrano)

发布于 2024-12-29 12:41:20 字数 430 浏览 5 评论 0原文

我在 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

但它不起作用。我的意思是该命令执行(它询问我密码并且没有给出错误),但配置文件中的所有更改仍然被忽略(即工作进程或数据库设置的数量)。

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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

戒ㄋ 2025-01-05 12:41:20

也许这是因为独角兽重启的方式。并非每个工作人员都会立即重新启动。这是为了实现零停机且不丢失任何请求。如果您想确实看到所做的更改,请尝试停止然后启动您的应用程序。有时我不得不这样做。当然,您可能会失去一些请求。

以下任务是我用于重新启动、停止和启动我的 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

希望这对您有帮助。

也许这个< /a> 文章很有趣。

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.

金橙橙 2025-01-05 12:41:20

看这里我的宝贝~
使用 USR2 重新启动 Unicorn 似乎不会重新加载Production.rb 设置

请记住:unicorn.rb 中的工作目录应该是:/your/cap/directory/current

而不是: File.expand_path("../..", FILE)

因为unicorn和linux软链接fork错误:软链接无法正常工作。

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.

嘦怹 2025-01-05 12:41:20

你应该尝试 capistrano-unicorn ,这就是我目前使用下面提到的默认钩子的方法。

设置

将库添加到您的Gemfile

ruby
组:开发做
gem 'capistrano-unicorn', :require =>;错误的
结尾

并将其加载到您的部署脚本中config/deploy.rb

ruby
需要“capistrano-unicorn”

添加 unicorn 重启任务钩子:

ruby
在 'deploy:restart', 'unicorn:reload' 之后 # 应用程序未预加载
在 'deploy:restart', 'unicorn:restart' 之后 # 应用程序已预加载
after 'deploy:restart', 'unicorn:duplicate' # before_fork 钩子实现(零停机部署)

You should give capistrano-unicorn a try, that's what I currently use with the default hooks mentioned below.

Setup

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 unicorn restart task hook:

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文