From c225d54de1c45ca6f756a6d3c32b9341c790334a Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 7 Aug 2019 22:11:07 -0500 Subject: [PATCH] capistrano: add `deploy:rolling` task (fix #4123). --- config/deploy.rb | 3 +++ lib/capistrano/tasks/app.rake | 32 +++++++++++++++++++++++++++++++ lib/capistrano/tasks/unicorn.rake | 4 ---- lib/capistrano/tasks/web.rake | 3 --- 4 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 lib/capistrano/tasks/app.rake diff --git a/config/deploy.rb b/config/deploy.rb index 88cebd9fd..794578a47 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -12,3 +12,6 @@ set :conditionally_migrate, true # run migrations on the primary app server set :migration_role, :app + +# how long unicorn:legacy_restart (used by deploy:rolling) waits until killing the old unicorn. +set :unicorn_restart_sleep_time, 10 diff --git a/lib/capistrano/tasks/app.rake b/lib/capistrano/tasks/app.rake new file mode 100644 index 000000000..1a0677fb9 --- /dev/null +++ b/lib/capistrano/tasks/app.rake @@ -0,0 +1,32 @@ +namespace :app do + set :rolling_deploy, false + + before "deploy:migrate", "app:disable" + after "deploy:published", "app:enable" + + task :disable do + if fetch(:rolling_deploy) + # do nothing + else + invoke "web:disable" + invoke "unicorn:terminate" + end + end + + task :enable do + if fetch(:rolling_deploy) + invoke "unicorn:legacy_restart" + else + invoke "unicorn:start" + invoke "web:enable" + end + end +end + +namespace :deploy do + desc "Deploy a rolling update without taking the site down for maintenance" + task :rolling do + set :rolling_deploy, true + invoke "deploy" + end +end diff --git a/lib/capistrano/tasks/unicorn.rake b/lib/capistrano/tasks/unicorn.rake index 1c7e41f1b..2200dd6cb 100644 --- a/lib/capistrano/tasks/unicorn.rake +++ b/lib/capistrano/tasks/unicorn.rake @@ -14,7 +14,3 @@ namespace :unicorn do end end end - -after "deploy:published", "unicorn:terminate" -after "deploy:published", "unicorn:kill" -after "deploy:published", "unicorn:start" diff --git a/lib/capistrano/tasks/web.rake b/lib/capistrano/tasks/web.rake index b39eb24e8..7a4e024ad 100644 --- a/lib/capistrano/tasks/web.rake +++ b/lib/capistrano/tasks/web.rake @@ -19,6 +19,3 @@ namespace :web do end end end - -before "deploy:started", "web:disable" -after "deploy:published", "web:enable"