mina-deploy / mina

Blazing fast deployer and server automation tool
https://rubygems.org/gems/mina
Other
4.34k stars 491 forks source link

(Doc) 0 downtime deploy example in Mina document? #619

Closed 1c7 closed 6 years ago

1c7 commented 6 years ago

Background info (2018-July-3)

using Puma + Rails 5.2 + Mina Already Googled how to do zero downtime deploy. so far didn't success

How to make puma restart with 0 downtime?

I already try phased_restart image image

But somehow it doesn't work for me. the following command

mina puma:phased_restart

still cost 10-30 second, website not responding in that time.

Here is my config/deploy.rb and puma.rb config file

config/deploy.rb

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, '[remove for Github issue]'
set :domain, '[remove]'
set :deploy_to, '[remove]'
set :repository, '[remove]'
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

puma.rb

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

Using Ubuntu 16.04

Please write a 0 downtime deploy guide for dummy

1c7 commented 6 years ago

Issue closed, wrong place

I should post this to puma, not mina