diff --git a/Capfile b/Capfile index cef760291..335828c06 100644 --- a/Capfile +++ b/Capfile @@ -12,6 +12,9 @@ require "capistrano/delayed_job" require "whenever/capistrano" require "rvm1/capistrano3" +require "capistrano/puma" +install_plugin Capistrano::Puma + #SCM: Git require "capistrano/scm/git" install_plugin Capistrano::SCM::Git diff --git a/Gemfile b/Gemfile index 5ad8bccfe..b13cc75a2 100644 --- a/Gemfile +++ b/Gemfile @@ -41,6 +41,7 @@ gem "paperclip", "~> 5.2.1" gem "paranoia", "~> 2.4.2" gem "pg", "~> 0.21.0" gem "pg_search", "~> 2.0.1" +gem "puma", "~> 4.2.1" gem "recipient_interceptor", "~> 0.2.0" gem "redcarpet", "~> 3.4.0" gem "responders", "~> 2.4.0" @@ -55,7 +56,6 @@ gem "translator-text", "~> 0.1.0" gem "turbolinks", "~> 2.5.3" gem "turnout", "~> 2.4.0" gem "uglifier", "~> 4.1.2" -gem "unicorn", "~> 5.4.1" gem "whenever", "~> 0.10.0", require: false gem "wicked_pdf", "~> 1.1.0" gem "wkhtmltopdf-binary", "~> 0.12.4" @@ -74,7 +74,6 @@ group :development, :test do gem "knapsack_pro", "~> 1.1.0" gem "launchy", "~> 2.4.3" gem "letter_opener_web", "~> 1.3.4" - gem "puma", "~> 4.1.1" gem "spring", "~> 2.0.1" gem "spring-commands-rspec", "~> 1.0.4" end @@ -94,6 +93,7 @@ group :development do gem "capistrano-bundler", "~> 1.2", require: false gem "capistrano-rails", "~> 1.4.0", require: false gem "capistrano3-delayed-job", "~> 1.7.3" + gem "capistrano3-puma", "~> 4.0.0" gem "erb_lint", require: false gem "mdl", "~> 0.5.0", require: false gem "rubocop", "~> 0.75.0", require: false diff --git a/Gemfile.lock b/Gemfile.lock index aa490cd70..dcb108500 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -116,6 +116,10 @@ GEM capistrano3-delayed-job (1.7.5) capistrano (~> 3.0, >= 3.0.0) daemons (~> 1.2.4) + capistrano3-puma (4.0.0) + capistrano (~> 3.7) + capistrano-bundler + puma (~> 4.0) capybara (2.17.0) addressable mini_mime (>= 0.1.3) @@ -301,7 +305,6 @@ GEM activerecord kaminari-core (= 1.1.1) kaminari-core (1.1.1) - kgio (2.11.2) knapsack_pro (1.1.0) rake kramdown (1.17.0) @@ -388,7 +391,7 @@ GEM activesupport (>= 4.2) arel (>= 6) public_suffix (4.0.1) - puma (4.1.1) + puma (4.2.1) nio4r (~> 2.0) rack (2.0.7) rack-accept (0.4.5) @@ -428,7 +431,6 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (3.0.0) - raindrops (0.19.0) rake (12.3.3) recipient_interceptor (0.2.0) mail @@ -554,9 +556,6 @@ GEM uglifier (4.1.19) execjs (>= 0.3.0, < 3) unicode-display_width (1.6.0) - unicorn (5.4.1) - kgio (~> 2.6) - raindrops (~> 0.7) uniform_notifier (1.11.0) user_agent_parser (2.4.1) uuidtools (2.1.5) @@ -598,6 +597,7 @@ DEPENDENCIES capistrano-bundler (~> 1.2) capistrano-rails (~> 1.4.0) capistrano3-delayed-job (~> 1.7.3) + capistrano3-puma (~> 4.0.0) capybara (~> 2.17.0) capybara-webmock (~> 0.5.3) ckeditor (~> 4.2.3) @@ -641,7 +641,7 @@ DEPENDENCIES paranoia (~> 2.4.2) pg (~> 0.21.0) pg_search (~> 2.0.1) - puma (~> 4.1.1) + puma (~> 4.2.1) rails (= 5.0.7.2) rails-assets-leaflet! rails-assets-markdown-it (~> 8.2.1)! @@ -669,7 +669,6 @@ DEPENDENCIES turbolinks (~> 2.5.3) turnout (~> 2.4.0) uglifier (~> 4.1.2) - unicorn (~> 5.4.1) web-console (~> 3.3.0) whenever (~> 0.10.0) wicked_pdf (~> 1.1.0) diff --git a/config/deploy.rb b/config/deploy.rb index c56d88f3e..de562dc58 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -8,6 +8,7 @@ end set :rails_env, fetch(:stage) set :rvm1_ruby_version, "2.3.2" +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) @@ -21,7 +22,7 @@ set :log_level, :info set :pty, true set :use_sudo, false -set :linked_files, %w[config/database.yml config/secrets.yml config/unicorn.rb config/environments/production.rb] +set :linked_files, %w[config/database.yml config/secrets.yml config/environments/production.rb] set :linked_dirs, %w[log tmp public/system public/assets public/ckeditor_assets] set :keep_releases, 5 @@ -35,7 +36,6 @@ set(:config_files, %w[ log_rotation database.yml secrets.yml - unicorn.rb ]) set :whenever_roles, -> { :app } @@ -50,6 +50,8 @@ namespace :deploy do after :published, "delayed_job:restart" after :published, "refresh_sitemap" + before "deploy:restart", "setup_puma" + after :finishing, "deploy:cleanup" desc "Deploys and runs the tasks needed to upgrade to a new release" @@ -94,3 +96,22 @@ task :execute_release_tasks do end end end + +desc "Create pid and socket folders needed by puma and convert unicorn sockets into symbolic links \ + to the puma socket, so legacy nginx configurations pointing to the unicorn socket keep working" +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" + + if test("[ -e #{shared_path}/tmp/sockets/unicorn.sock ]") + execute "ln -sf #{shared_path}/tmp/sockets/puma.sock #{shared_path}/tmp/sockets/unicorn.sock; true" + end + + if test("[ -e #{shared_path}/sockets/unicorn.sock ]") + execute "ln -sf #{shared_path}/tmp/sockets/puma.sock #{shared_path}/sockets/unicorn.sock; true" + end + end + end +end diff --git a/lib/capistrano/tasks/restart.cap b/lib/capistrano/tasks/restart.cap deleted file mode 100644 index 54c90819a..000000000 --- a/lib/capistrano/tasks/restart.cap +++ /dev/null @@ -1,10 +0,0 @@ -namespace :deploy do - desc 'Commands for unicorn application' - %w(start stop force-stop restart upgrade reopen-logs).each do |command| - task command.to_sym do - on roles(:app), in: :sequence, wait: 5 do - execute "/etc/init.d/unicorn_#{fetch(:full_app_name)} #{command}" - end - end - end -end