Created
January 14, 2015 01:33
-
-
Save kripy/d59fbcdd5573a5ecfbd6 to your computer and use it in GitHub Desktop.
Heroku Sequel Fork
This file contains hidden or 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
# Using Sequel with Sinatra (Unicorn) on Heroku and getting this error: | |
# Sequel::DatabaseDisconnectError - PG::ConnectionBad: PQconsumeInput() SSL error: decryption failed or bad record mac. | |
# Need to do some forking. | |
# In unicorn.rb: | |
worker_processes 4 # amount of unicorn workers to spin up | |
timeout 30 # restarts workers that hang for 30 seconds | |
preload_app true # avoid regeneration of jekyll site for each fork | |
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?(Sequel::Model) and | |
Sequel::Model.db.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?(Sequel::Model) and | |
Sequel::Model.db.connect(ENV['DATABASE_URL'] || 'postgres://user@localhost/database') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment