我在 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 能否继续使用旧的工作进程?