Merge pull request #3850 from consul/puma_rb

Add puma configuration to version control
This commit is contained in:
Javier Martín
2019-11-14 13:31:11 +01:00
committed by GitHub
11 changed files with 70 additions and 39 deletions

View File

@@ -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"

View File

@@ -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)!

View File

@@ -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"

View File

@@ -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]

View File

@@ -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)

View File

@@ -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]

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,5 @@
#!/usr/bin/env puma
_load_from File.expand_path("../../puma.rb", __FILE__)
environment "preproduction"

View File

@@ -0,0 +1,5 @@
#!/usr/bin/env puma
_load_from File.expand_path("../../puma.rb", __FILE__)
environment "production"

5
config/puma/staging.rb Normal file
View File

@@ -0,0 +1,5 @@
#!/usr/bin/env puma
_load_from File.expand_path("../../puma.rb", __FILE__)
environment "staging"