Skip to content

Instantly share code, notes, and snippets.

@kripy
Created January 14, 2015 01:33
Show Gist options
  • Save kripy/d59fbcdd5573a5ecfbd6 to your computer and use it in GitHub Desktop.
Save kripy/d59fbcdd5573a5ecfbd6 to your computer and use it in GitHub Desktop.
Heroku Sequel Fork
# 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