Puma + Mina + Rails 5.2 + Ubuntu 16.04
部署新代码期间网站依然可用,而不是卡 10-30 秒
发帖子前我谷歌查了半天依然搞不定,想看看大家的做法。
目前服务器我用的是 Puma。phased_restart 已经配置了
用了 mina-puma
gem:https://github.com/untitledkingdom/mina-puma
mina puma:phased_restart
跑如上命令也毫无问题。结果如下图:
phased_restart 期间,网站有 10 秒 -30 秒不响应
大家是怎么做无缝部署的?(0 downtime deploy)
如果有人用 puma 实现过无缝部署,能分享下经验吗?
config/deploy.rb
(Mina) config/puma.rb
(Puma 配置文件)require 'mina/rails'
require 'mina/git'
require 'mina/rvm' # for rvm support. (https://rvm.io)
require 'mina/puma' # https://github.com/untitledkingdom/mina-puma
set :application_name, '因隐私原因删除掉原有值'
set :domain, '因隐私原因删除掉原有值'
set :deploy_to, '因隐私原因删除掉原有值'
set :repository, '因隐私原因删除掉原有值'
set :branch, 'master'
set :user, 'ubuntu' # Username in the server to SSH to.
set :port, '22' # SSH port number.
set :forward_agent, true # SSH forward_agent.
# For mina-puma
set :pumactl_socket, '/tmp/witt.sock'
set :puma_state, "/var/www/witticism.com/shared/tmp/sockets/puma.state"
set :puma_pid, "/var/www/witticism.com/shared/tmp/pids/puma.pid"
task :remote_environment do
invoke :'rvm:use', 'ruby-2.4.1@default'
end
desc "Deploys the current version to the server."
task :deploy do
deploy do
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
invoke :'rails:db_migrate'
invoke :'deploy:cleanup'
on :launch do
in_path(fetch(:current_path)) do
command %{mkdir -p tmp/}
command %{touch tmp/restart.txt}
end
end
end
end
bind "unix:///tmp/witt.sock"
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count
environment ENV.fetch("RAILS_ENV") { "production" }
app_name = "witticism.com"
app_dir = File.expand_path("../..", __FILE__)
app_dir_parent = File.expand_path("../../", __FILE__)
application_path = "#{app_dir}"
pidfile "/var/www/witticism.com/shared/tmp/pids/puma.pid"
state_path "/var/www/witticism.com/shared/tmp/sockets/puma.state"
workers ENV.fetch("WEB_CONCURRENCY") { 2 }
before_fork do
ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
end
on_worker_boot do
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end