Files
grecia/config/deploy.rb
Javi Martín 40b3c9f2ce Make sure Puma has restarted properly
We were getting an error when restarting Puma after upgrading Ruby. Even
if the restart command was sent successfully, Puma silently crashed and
the log had the following error:

/home/deploy/.rvm/rubies/ruby-2.4.9/lib/ruby/site_ruby/2.4.0/bundler/spec_set.rb:91:in
`block in materialize': Could not find rake-13.0.1 in any of the sources
(Bundler::GemNotFound)

So it looks like the crash happens because Puma was started when the
application used Ruby 2.4 and now when it's restarted it still tries to
use Ruby 2.4, even if the application now uses Ruby 2.5.

I haven't found a proper way to configure Puma so we can avoid this, so
as a workaround I've added the `puma:start` task after restarting Puma.
If Puma was successfully restarted, `puma:start` will do nothing; if
Puma crashed, `puma:start` will start it.

To guarantee the tasks will be executed in the proper order, the tasks
introduced by capistrano3-delayed_job and capistrano3-puma are cleared,
and then we configure the order so first we restart Puma, then restart
the Delayed Jobs processes (so there's enough time for Puma to crash if
Ruby was upgraded) and then start Puma.
2020-09-16 10:53:22 +02:00

120 lines
2.9 KiB
Ruby

# config valid only for current version of Capistrano
lock "~> 3.10.1"
def deploysecret(key)
@deploy_secrets_yml ||= YAML.load_file("config/deploy-secrets.yml")[fetch(:stage).to_s]
@deploy_secrets_yml.fetch(key.to_s, "undefined")
end
set :rails_env, fetch(:stage)
set :rvm1_map_bins, -> { fetch(:rvm_map_bins).to_a.concat(%w[rake gem bundle ruby]).uniq }
set :application, "consul"
set :full_app_name, deploysecret(:full_app_name)
set :deploy_to, deploysecret(:deploy_to)
set :server_name, deploysecret(:server_name)
set :db_server, deploysecret(:db_server)
set :ssh_options, port: deploysecret(:ssh_port)
set :repo_url, "https://github.com/consul/consul.git"
set :revision, `git rev-parse --short #{fetch(:branch)}`.strip
set :log_level, :info
set :pty, true
set :use_sudo, false
set :linked_files, %w[config/database.yml config/secrets.yml]
set :linked_dirs, %w[log tmp public/system public/assets public/ckeditor_assets]
set :keep_releases, 5
set :local_user, ENV["USER"]
set :puma_conf, "#{release_path}/config/puma/#{fetch(:rails_env)}.rb"
set :delayed_job_workers, 2
set :delayed_job_roles, :background
set(:config_files, %w[
log_rotation
database.yml
secrets.yml
])
set :whenever_roles, -> { :app }
namespace :deploy do
Rake::Task["delayed_job:default"].clear_actions
Rake::Task["puma:smart_restart"].clear_actions
after :updating, "rvm1:install:rvm"
after :updating, "rvm1:install:ruby"
after :updating, "install_bundler_gem"
after "deploy:migrate", "add_new_settings"
after :publishing, "setup_puma"
after :published, "deploy:restart"
before "deploy:restart", "puma:restart"
before "deploy:restart", "delayed_job:restart"
before "deploy:restart", "puma:start"
after :finished, "refresh_sitemap"
desc "Deploys and runs the tasks needed to upgrade to a new release"
task :upgrade do
after "add_new_settings", "execute_release_tasks"
invoke "deploy"
end
end
task :install_bundler_gem do
on roles(:app) do
within release_path do
execute :rvm, fetch(:rvm1_ruby_version), "do", "gem install bundler --version 1.17.1"
end
end
end
task :refresh_sitemap do
on roles(:app) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, "sitemap:refresh:no_ping"
end
end
end
end
task :add_new_settings do
on roles(:db) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, "settings:add_new_settings"
end
end
end
end
task :execute_release_tasks do
on roles(:app) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, "consul:execute_release_tasks"
end
end
end
end
desc "Create pid and socket folders needed by puma"
task :setup_puma do
on roles(:app) do
with rails_env: fetch(:rails_env) do
execute "mkdir -p #{shared_path}/tmp/sockets; true"
execute "mkdir -p #{shared_path}/tmp/pids; true"
end
end
end