diff --git a/Gemfile b/Gemfile index 8da6cd866..34a39b987 100644 --- a/Gemfile +++ b/Gemfile @@ -52,7 +52,7 @@ gem 'sassc-rails' gem 'uglifier', '>= 1.0.3' -gem 'puma', '~> 3.4' +gem 'unicorn', '~> 5.1' gem 'rack-piwik', '~> 0.3.0', require: 'rack/piwik' diff --git a/Gemfile.lock b/Gemfile.lock index daf4e9fca..deae5f141 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -255,6 +255,7 @@ GEM jquery-ui-rails (6.0.1) railties (>= 3.2.16) jsonapi-renderer (0.2.2) + kgio (2.11.4) launchy (2.5.2) addressable (~> 2.8) letter_opener (1.8.1) @@ -327,7 +328,6 @@ GEM method_source (~> 1.0) psych (3.3.3) public_suffix (5.0.1) - puma (3.12.6) racc (1.7.1) rack (2.2.6.4) rack-attack (6.7.0) @@ -367,6 +367,7 @@ GEM rake (>= 12.2) thor (~> 1.0) rainbow (3.1.1) + raindrops (0.20.1) rake (13.0.6) rb-fsevent (0.11.2) rb-inotify (0.10.1) @@ -450,6 +451,9 @@ GEM execjs (>= 0.3.0, < 3) unaccent (0.4.0) unicode-display_width (1.4.1) + unicorn (5.8.0) + kgio (~> 2.6) + raindrops (~> 0.7) uniform_notifier (1.16.0) warden (1.2.9) rack (>= 2.0.9) @@ -508,7 +512,6 @@ DEPENDENCIES poltergeist (= 1.18.1) pry psych (< 4.0) - puma (~> 3.4) rack-attack rack-piwik (~> 0.3.0) rack-timeout @@ -524,6 +527,7 @@ DEPENDENCIES simple_form stackprof uglifier (>= 1.0.3) + unicorn (~> 5.1) webrick (~> 1.7) RUBY VERSION diff --git a/Procfile b/Procfile index c2c566e8c..9c8237414 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: bundle exec puma -C config/puma.rb +web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index f76c7253d..382436855 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -229,6 +229,7 @@ def profiles_for_index def build_categories_and_tags_for_tags_filter @categories = Category.sorted_categories + # builds variables like @tags_internet Category.all.includes(:translations).each do |category| tags = ActsAsTaggableOn::Tag .belongs_to_category(category.id) diff --git a/config/honeybadger.yml b/config/honeybadger.yml index e1449d75f..c923a866d 100644 --- a/config/honeybadger.yml +++ b/config/honeybadger.yml @@ -22,8 +22,8 @@ development_environments: # revision: null # Enable verbose debug logging (useful for troubleshooting). -debug: true +debug: false # Enable Honeybadger Insights insights: - enabled: true + enabled: false diff --git a/config/puma.rb b/config/puma.rb deleted file mode 100644 index 0aa72dba9..000000000 --- a/config/puma.rb +++ /dev/null @@ -1,15 +0,0 @@ -workers Integer(ENV['WEB_CONCURRENCY'] || 1) -threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5) -threads threads_count, threads_count - -preload_app! - -rackup DefaultRackup if defined?(DefaultRackup) -port ENV['PORT'] || 3000 -environment ENV['RACK_ENV'] || 'development' - -on_worker_boot do - # Worker-specific setup for Rails 4.1 to 5.2, after 5.2 it's not needed - # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot - ActiveRecord::Base.establish_connection -end diff --git a/config/unicorn.rb b/config/unicorn.rb new file mode 100644 index 000000000..000dc0ce7 --- /dev/null +++ b/config/unicorn.rb @@ -0,0 +1,22 @@ +worker_processes Integer(ENV["WEB_CONCURRENCY"] || 1) +timeout 15 +preload_app true + +before_fork do |server, worker| + Signal.trap 'TERM' do + puts 'Unicorn master intercepting TERM and sending myself QUIT instead' + Process.kill 'QUIT', Process.pid + end + + defined?(ActiveRecord::Base) and + ActiveRecord::Base.connection.disconnect! +end + +after_fork do |server, worker| + Signal.trap 'TERM' do + puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT' + end + + defined?(ActiveRecord::Base) and + ActiveRecord::Base.establish_connection +end