Skip to content

Instantly share code, notes, and snippets.

@floere
Created March 17, 2010 21:34
Show Gist options
  • Save floere/335735 to your computer and use it in GitHub Desktop.
Save floere/335735 to your computer and use it in GitHub Desktop.
# In your unicorn.rb
#
after_fork do |server, worker|
GC.disable
end
# The rack app.
#
Responder = lambda do |env|
harakiri
# Your app here
end
# In the same scope as the Responder:
#
@@requests = 0
@@quit_after_requests = 50
def harakiri
@@requests = @@requests + 1
# Kill yourself off, by means of a quick slice.
# Will finish the request in Unicorn with honor, then die.
# Unicorn will fork you a new one.
Process.kill(:QUIT, Process.pid) if @@requests > @@quit_after_requests
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment