Using unicorn with heroku (cedar stack)
Posted: 2012-02-17
Updated: 2012-02-17
To use Unicorn instead of thin on heroku, do the following:
- Add
gem "unicorn"to yourGemfile - Add a
Procfile - Add
config/unicorn.rb
Procfile
1 web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
2 worker: bundle exec rake jobs:work
Note: worker is not required, I just mentioned it because you might need it.
unicorn.rb
1 preload_app true
2 worker_processes 4 # amount of unicorn workers to spin up
3 timeout 30 # restarts workers that hang for 30 seconds
4 after_fork do |server, worker|
5 defined?(ActiveRecord::Base) and
6 ActiveRecord::Base.establish_connection
7 end
Note: the after_fork is required to avoid SSL errors with postgresql.