Created
October 31, 2012 13:51
-
-
Save subelsky/3987140 to your computer and use it in GitHub Desktop.
Setting up Puma and Rails on Heroku
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gemfile | |
gem "puma" | |
# Procfile | |
web: bundle exec puma -p $PORT -e $RACK_ENV -C config/puma.rb | |
# add to config block config/environments/production.rb | |
config.threadsafe! | |
# get rid of NewRelic after_fork code, if you were doing this: | |
# http://support.newrelic.com/kb/troubleshooting/unicorn-no-data | |
# and get rid of config/unicorn.rb if you were using that | |
# config/puma.rb | |
require "active_record" | |
cwd = File.dirname(__FILE__)+"/.." | |
ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished | |
ActiveRecord::Base.establish_connection(ENV["DATABASE_URL"] || YAML.load_file("#{cwd}/config/database.yml")[ENV["RACK_ENV"]]) | |
ActiveRecord::Base.verify_active_connections! | |
# if you use NewRelic, set your NEWRELIC_DISPATCHER environment variable on heroku, per | |
# https://github.com/puma/puma/issues/128 - may not be needed for future releases of Puma | |
heroku config:add NEWRELIC_DISPATCHER=Puma |
config.threadsafe! is deprecated for rails 4:
"Rails applications behave by default as thread safe in production as long as config.cache_classes and config.eager_load are set to true."
ActiveRecord::Base.verify_active_connections!
is also deprecated, and should be removed.
yeah you don't need a puma.rb file. That was vestigial from when I was on unicorn, and I thought had read somewhere that puma needed it to be able to restart cleanly
here's the relevant info for the new cool way to do it https://devcenter.heroku.com/articles/concurrency-and-database-connections#connection-pool
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An alternative approach that helps increase AR's connection pool size on Heroku has been published in the Heroku dev center.