1

我在 MRI 2.1.0 上使用 Puma 作为 Rails 4 项目的应用程序服务器。我正在使用 Capistrano 3 来处理部署。一切都像魅力一样运作。但是,我最近注意到我的部署过程存在问题。如果我随后更改我的 Gemfile,puma 无法完成分阶段重启,最终所有工作人员都会被杀死。我在集群模式下运行 Puma 并preload_app!设置为 true。

这是我处理分阶段重启的 Capistrano 配方。

desc "Restart the application (phased restart)"
task :phased_restart do
  on roles(:app) do |h|
    execute "cd #{fetch(:current_path)} && bundle exec pumactl -S #{fetch(:puma_state)}     phased-restart", :pty => true
  end
end

这是 Capistrano 日志的截断输出。

DEBUG [4790766f] Command: cd /home/app/current && bundle exec pumactl -S /home/app/shared/tmp/pids/puma.state phased-restart
DEBUG [de00176a]    Command phased-restart sent success
 INFO [de00176a] Finished in 0.909 seconds with exit status 0 (successful).

这是我的config/puma.rb文件。

#!/usr/bin/env puma
require 'active_support'

environment 'production'
daemonize
pidfile '/home/app/shared/tmp/pids/puma.pid'
state_path '/home/app/shared/tmp/pids/puma.state'
stdout_redirect 'log/puma_stdout.log', 'log/puma_stderr.log'
threads 100, 100

bind 'tcp://0.0.0.0:9292'
bind 'unix:////home/app/shared/tmp/pids/puma.sock'

on_worker_boot do
  ActiveSupport.on_load(:active_record) do
  ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
  ActiveRecord::Base.establish_connection(YAML.load_file("#{Rails.root}/config/database.yml")[Rails.env])
  end
end
workers 4
preload_app!

有人在我的 puma 配置文件中看到任何问题吗?

所以,目前我会bundle exec cap production deploy:start在发生这种情况时启动 Puma。但是,我希望在每种情况下都实现零停机部署。

如果无法启动新的衍生进程,Puma 能否继续使用旧的工作进程?

4

2 回答 2

4

你知道preload_app!与分阶段重启冲突?

证明:https ://github.com/puma/puma/blob/0ea7af5e2cc8fa192ec82934a4a47880bdb592f8/lib/puma/configuration.rb#L333-L335

我认为首先你需要决定使用哪个。

于 2014-04-08T12:49:22.533 回答
4

要进行分阶段重启,您需要启用 prune_bundler 选项并禁用 preload_app!见https://github.com/puma/puma/blob/master/DEPLOYMENT.md#restarting

要使用 Capistrano 进行零停机部署,您可以使用 capistrano3-puma gem 和以下选项:

set :puma_preload_app, false
set :puma_prune_bundler, true
于 2014-11-07T10:52:16.430 回答