diff --git a/config/deploy.rb b/config/deploy.rb index 49fbfe295..c98966459 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -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" 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"