Add puma configuration to version control
We were using Capistrano's shared folder because it was the default folder used by the capistrano-puma gem. However, it's easier to manage it if it's under version control. So we're moving the old `puma.rb` to `puma/development.rb`, and we use the new `puma.rb` file for all environments except development. Anyone installing CONSUL can change these files at will or change the specific files for preproduction, production and staging environments.
This commit is contained in:
@@ -31,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
|
||||
@@ -48,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"
|
||||
|
||||
@@ -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
|
||||
|
||||
11
config/puma/development.rb
Normal file
11
config/puma/development.rb
Normal 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
|
||||
5
config/puma/preproduction.rb
Normal file
5
config/puma/preproduction.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env puma
|
||||
|
||||
_load_from File.expand_path("../../puma.rb", __FILE__)
|
||||
|
||||
environment "preproduction"
|
||||
5
config/puma/production.rb
Normal file
5
config/puma/production.rb
Normal 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
5
config/puma/staging.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env puma
|
||||
|
||||
_load_from File.expand_path("../../puma.rb", __FILE__)
|
||||
|
||||
environment "staging"
|
||||
Reference in New Issue
Block a user