From 40619f9d97981d0a70f72a761fd85a26d3a2fbd2 Mon Sep 17 00:00:00 2001 From: Andy Pliszka and Joe Masilotti Date: Tue, 16 Apr 2013 14:23:00 -0400 Subject: [PATCH] Switches web server to a blessing of 6 unicorns --- Gemfile | 5 +---- Gemfile.lock | 12 +++++++----- Procfile | 2 +- config/unicorn.rb | 24 ++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 config/unicorn.rb diff --git a/Gemfile b/Gemfile index 089982edb..5b2cc7154 100644 --- a/Gemfile +++ b/Gemfile @@ -37,15 +37,12 @@ gem "eventmachine" gem "em-http-request", ">= 1.0.0.beta.4" gem 'newrelic_rpm' gem 'hashie', '~>1.2' # TODO: We need to hardcode Hashie for now to avoid circular dependency in bundler update resolution +gem 'unicorn' group :production do gem "therubyracer" end -group :thin do - gem "thin" -end - group :assets do gem "compass-rails" gem "sass-rails" diff --git a/Gemfile.lock b/Gemfile.lock index 5582ee789..661f207ff 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -189,6 +189,7 @@ GEM json (1.5.5) jwt (0.1.5) multi_json (>= 1.0) + kgio (2.8.0) launchy (2.2.0) addressable (~> 2.3) libv8 (3.11.8.13) @@ -277,6 +278,7 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) + raindrops (0.10.0) rake (10.0.3) rb-fsevent (0.9.3) rdoc (3.12.2) @@ -332,10 +334,6 @@ GEM therubyracer (0.11.3) libv8 (~> 3.11.8.12) ref - thin (1.5.0) - daemons (>= 1.0.9) - eventmachine (>= 0.12.6) - rack (>= 1.0.0) thor (0.17.0) tilt (1.3.6) timecop (0.5.9.2) @@ -346,6 +344,10 @@ GEM uglifier (1.3.0) execjs (>= 0.3.0) multi_json (~> 1.0, >= 1.0.2) + unicorn (4.6.2) + kgio (~> 2.6) + rack + raindrops (~> 0.7) vagrant (1.0.6) archive-tar-minitar (= 0.5.2) childprocess (~> 0.3.1) @@ -429,9 +431,9 @@ DEPENDENCIES selenium-webdriver (>= 2.25.0) shoulda-matchers therubyracer - thin timecop uglifier + unicorn vagrant vcr (= 2.2.4) whenever diff --git a/Procfile b/Procfile index e85bc31fc..793489725 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ -web: bundle exec thin start -p $PORT +web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb worker: bundle exec rake jobs:work diff --git a/config/unicorn.rb b/config/unicorn.rb new file mode 100644 index 000000000..9e478e033 --- /dev/null +++ b/config/unicorn.rb @@ -0,0 +1,24 @@ +worker_processes Integer(ENV["WEB_CONCURRENCY"] || 6) +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