diff --git a/Gemfile b/Gemfile index c25039e..2b51a8b 100644 --- a/Gemfile +++ b/Gemfile @@ -31,6 +31,7 @@ gem 'json_builder' gem "statsd-ruby", :require => "statsd" # gem 'trashed', :git => 'https://github.com/ninetwentyfour/trashed.git' gem 'impressionist' +gem 'unicorn' # heroku gems for pulling/pushing db # gem 'heroku' @@ -56,7 +57,7 @@ group :production do gem 'airbrake' gem 'home_run', :require=>'date' #gem 'slim_scrooge', :git => "git://github.com/sdsykes/slim_scrooge.git" - gem 'thin' + # gem 'thin' gem 'pg' gem 'newrelic_rpm' gem 'heroku' diff --git a/Gemfile.lock b/Gemfile.lock index 0be3d36..5c59df9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -119,7 +119,6 @@ GEM capybara (>= 1.1.2) cucumber (>= 1.1.8) nokogiri (>= 1.5.0) - daemons (1.1.9) dalli (2.6.0) database_cleaner (0.9.1) devise (2.2.3) @@ -201,6 +200,7 @@ GEM redis jwt (0.1.5) multi_json (>= 1.0) + kgio (2.8.0) launchy (2.1.2) addressable (~> 2.3) less (2.2.2) @@ -295,6 +295,7 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) + raindrops (0.10.0) rake (10.0.3) rdoc (3.12.1) json (~> 1.4) @@ -352,10 +353,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.3) treetop (1.4.12) @@ -372,6 +369,10 @@ GEM unf (0.0.5) unf_ext unf_ext (0.0.5) + unicorn (4.6.1) + kgio (~> 2.6) + rack + raindrops (~> 0.7) uuidtools (2.1.3) warden (1.2.1) rack (>= 1.0) @@ -437,9 +438,9 @@ DEPENDENCIES spreadsheet statsd-ruby therubyracer - thin to_xls! twitter uglifier + unicorn uuidtools will_paginate diff --git a/Procfile b/Procfile index edddd4f..9249f1e 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: bundle exec thin start -p $PORT -e $RACK_ENV \ No newline at end of file +web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb \ No newline at end of file diff --git a/config/environments/production.rb b/config/environments/production.rb index 29b8469..e3342b6 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -73,4 +73,8 @@ # Generate digests for assets URLs config.assets.digest = true + + # handle logging with unicorn and heroku + config.logger = Logger.new(STDOUT) + config.logger.level = Logger.const_get(ENV['LOG_LEVEL'] ? ENV['LOG_LEVEL'].upcase : 'INFO') end diff --git a/config/initializers/newrelic_reconnect.rb b/config/initializers/newrelic_reconnect.rb new file mode 100644 index 0000000..ec06c26 --- /dev/null +++ b/config/initializers/newrelic_reconnect.rb @@ -0,0 +1,8 @@ +# config/initailizers/newrelic_reconnect.rb + +# Ensure the agent is started using Unicorn +# This is needed when using Unicorn and preload_app is NOT set to true. +# https://newrelic.com/docs/ruby/no-data-with-unicorn +if Rails.env.production? + NewRelic::Agent.after_fork(:force_reconnect => true) if defined? Unicorn +end \ No newline at end of file diff --git a/config/unicorn.rb b/config/unicorn.rb new file mode 100644 index 0000000..c28154f --- /dev/null +++ b/config/unicorn.rb @@ -0,0 +1,9 @@ +# config/unicorn.rb + +# Minimal Heroku unicorn config +# * I found no real gain from enabling preload_app on Heroku (which makes for faster worker starts/restarts), +# and it will cause strange issues if you don't re-establish all connections correctly +# * Heroku has a 30s timeout so we set to 60, allowing them to handle timeouts and issue an H12 error +# * Depending on your memory usage workers can be bumped to 3-4. With Sinatra it can be 8+ +worker_processes 3 +timeout 60 \ No newline at end of file