Ash*_*sta 1 deployment capistrano ruby-on-rails puma ruby-on-rails-4
我使用 Puma 作为 MRI 2.1.0 上的 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
Run Code Online (Sandbox Code Playgroud)
这是 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).
Run Code Online (Sandbox Code Playgroud)
这是我的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!
Run Code Online (Sandbox Code Playgroud)
有人看到我的 puma 配置文件有什么问题吗?
所以,目前我会bundle exec cap production deploy:start在这种情况发生时启动 Puma。但是,我希望在每种情况下都能实现零停机部署。
如果无法启动新生成的进程,Puma 可以继续使用旧的工作进程吗?
| 归档时间: |
|
| 查看次数: |
3178 次 |
| 最近记录: |