diff --git a/Gemfile b/Gemfile index 6a61d3a1c..0ba6fef9e 100644 --- a/Gemfile +++ b/Gemfile @@ -40,7 +40,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 "puma", "~> 4.3.0" gem "recipient_interceptor", "~> 0.2.0" gem "redcarpet", "~> 3.4.0" gem "responders", "~> 2.4.0" diff --git a/Gemfile.lock b/Gemfile.lock index 202781cd1..75e38a36d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -337,7 +337,7 @@ GEM net-ssh (>= 2.6.5) net-ssh (5.0.2) newrelic_rpm (4.1.0.333) - nio4r (2.3.1) + nio4r (2.5.2) nokogiri (1.10.4) mini_portile2 (~> 2.4.0) nori (2.6.0) @@ -385,7 +385,7 @@ GEM activesupport (>= 4.2) arel (>= 6) public_suffix (4.0.1) - puma (4.2.1) + puma (4.3.0) nio4r (~> 2.0) rack (2.0.7) rack-accept (0.4.5) @@ -638,7 +638,7 @@ DEPENDENCIES paranoia (~> 2.4.2) pg (~> 0.21.0) pg_search (~> 2.0.1) - puma (~> 4.2.1) + puma (~> 4.3.0) rails (= 5.0.7.2) rails-assets-leaflet! rails-assets-markdown-it (~> 8.2.1)! diff --git a/config/deploy.rb b/config/deploy.rb index b3037b6e6..c98966459 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -11,8 +11,11 @@ set :rvm1_map_bins, -> { fetch(:rvm_map_bins).to_a.concat(%w[rake gem bundle rub 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 @@ -28,10 +31,7 @@ set :keep_releases, 5 set :local_user, ENV["USER"] -set :puma_restart_command, "bundle exec --keep-file-descriptors puma" -set :puma_workers, 2 -set :puma_preload_app, true -set :puma_init_active_record, true +set :puma_conf, "#{release_path}/config/puma/#{fetch(:rails_env)}.rb" set :delayed_job_workers, 2 set :delayed_job_roles, :background @@ -45,6 +45,8 @@ set(:config_files, %w[ set :whenever_roles, -> { :app } namespace :deploy do + Rake::Task["puma:check"].clear_actions + before :starting, "rvm1:install:rvm" before :starting, "rvm1:install:ruby" before :starting, "install_bundler_gem" diff --git a/config/deploy/preproduction.rb b/config/deploy/preproduction.rb index f7b2ade9f..7bbc3755a 100644 --- a/config/deploy/preproduction.rb +++ b/config/deploy/preproduction.rb @@ -1,10 +1,4 @@ -set :deploy_to, deploysecret(:deploy_to) -set :server_name, deploysecret(:server_name) -set :db_server, deploysecret(:db_server) set :branch, ENV["branch"] || :master -set :ssh_options, port: deploysecret(:ssh_port) -set :stage, :preproduction -set :rails_env, :preproduction server deploysecret(:server1), user: deploysecret(:user), roles: %w[web app db importer cron background] server deploysecret(:server2), user: deploysecret(:user), roles: %w[web app db importer] diff --git a/config/deploy/production.rb b/config/deploy/production.rb index 6f1524a8c..73cc0679a 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -1,10 +1,4 @@ -set :deploy_to, deploysecret(:deploy_to) -set :server_name, deploysecret(:server_name) -set :db_server, deploysecret(:db_server) set :branch, :master -set :ssh_options, port: deploysecret(:ssh_port) -set :stage, :production -set :rails_env, :production server deploysecret(:server1), user: deploysecret(:user), roles: %w[web app db importer cron background] #server deploysecret(:server2), user: deploysecret(:user), roles: %w(web app db importer cron background) diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb index fe873d00e..7ef6191e4 100644 --- a/config/deploy/staging.rb +++ b/config/deploy/staging.rb @@ -1,9 +1,3 @@ -set :deploy_to, deploysecret(:deploy_to) -set :server_name, deploysecret(:server_name) -set :db_server, deploysecret(:db_server) set :branch, ENV["branch"] || :master -set :ssh_options, port: deploysecret(:ssh_port) -set :stage, :staging -set :rails_env, :staging server deploysecret(:server), user: deploysecret(:user), roles: %w[web app db importer cron] diff --git a/config/puma.rb b/config/puma.rb index 6cf278e41..2389e7907 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,15 +1,36 @@ -# ATTENTION: This file is only used to run puma on your development -# machine. To configure puma on production environments, use the -# `puma.rb` file in Capistrano's `shared` folder. +#!/usr/bin/env puma -# Puma can serve each request in a thread from an internal thread pool. -# Default is set to 5 threads for minimum and maximum, matching the -# default thread size of Active Record. -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i -threads threads_count, threads_count +rails_root = File.expand_path("../..", __FILE__) -port ENV.fetch("PORT") { 3000 } -environment ENV.fetch("RAILS_ENV") { "development" } +directory rails_root +rackup "#{rails_root}/config.ru" +environment "production" -# Allow puma to be restarted by `rails restart` command. -plugin :tmp_restart +tag "" + +pidfile "#{rails_root}/tmp/pids/puma.pid" +state_path "#{rails_root}/tmp/pids/puma.state" +stdout_redirect "#{rails_root}/log/puma_access.log", "#{rails_root}/log/puma_error.log", true + +bind "unix://#{rails_root}/tmp/sockets/puma.sock" + +threads 0, 16 +workers 2 +preload_app! + +restart_command "bundle exec --keep-file-descriptors puma" + +on_restart do + puts "Refreshing Gemfile" + ENV["BUNDLE_GEMFILE"] = "" +end + +before_fork do + ActiveRecord::Base.connection_pool.disconnect! +end + +on_worker_boot do + ActiveSupport.on_load(:active_record) do + ActiveRecord::Base.establish_connection + end +end diff --git a/config/puma/development.rb b/config/puma/development.rb new file mode 100644 index 000000000..d073c1087 --- /dev/null +++ b/config/puma/development.rb @@ -0,0 +1,11 @@ +# Puma can serve each request in a thread from an internal thread pool. +# Default is set to 5 threads for minimum and maximum, matching the +# default thread size of Active Record. +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i +threads threads_count, threads_count + +port ENV.fetch("PORT") { 3000 } +environment "development" + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart diff --git a/config/puma/preproduction.rb b/config/puma/preproduction.rb new file mode 100644 index 000000000..662d717be --- /dev/null +++ b/config/puma/preproduction.rb @@ -0,0 +1,5 @@ +#!/usr/bin/env puma + +_load_from File.expand_path("../../puma.rb", __FILE__) + +environment "preproduction" diff --git a/config/puma/production.rb b/config/puma/production.rb new file mode 100644 index 000000000..7b693ef07 --- /dev/null +++ b/config/puma/production.rb @@ -0,0 +1,5 @@ +#!/usr/bin/env puma + +_load_from File.expand_path("../../puma.rb", __FILE__) + +environment "production" diff --git a/config/puma/staging.rb b/config/puma/staging.rb new file mode 100644 index 000000000..1097290ea --- /dev/null +++ b/config/puma/staging.rb @@ -0,0 +1,5 @@ +#!/usr/bin/env puma + +_load_from File.expand_path("../../puma.rb", __FILE__) + +environment "staging"