Skip to content

Instantly share code, notes, and snippets.

@fraank
Created April 22, 2015 09:07
Show Gist options
  • Save fraank/5d452905bdd38fb1a4cf to your computer and use it in GitHub Desktop.
Save fraank/5d452905bdd38fb1a4cf to your computer and use it in GitHub Desktop.
unicorn config file for EventMachine for development-use
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
before_fork do |server,worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server,worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
if defined?(EventMachine)
unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive?
if EventMachine.reactor_running?
EventMachine.stop_event_loop
EventMachine.release_machine
EventMachine.instance_variable_set("@reactor_running",false)
end
Thread.new { EventMachine.run }
end
end
Signal.trap("INT") { EventMachine.stop }
Signal.trap("TERM") { EventMachine.stop }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment