Skip to content

Instantly share code, notes, and snippets.

@fuse
Created November 15, 2011 10:43
Show Gist options
  • Save fuse/1366748 to your computer and use it in GitHub Desktop.
Save fuse/1366748 to your computer and use it in GitHub Desktop.
Unicorn configuration
# unicorn_rails -c config/unicorn.rb -E production -D
worker_processes 4
user "synbioz", "users"
working_directory "/var/www/fake/current"
listen "/var/www/fake/shared/sockets/unicorn.sock", :backlog => 1024
pid "/var/www/fake/shared/pids/unicorn.pid"
# nuke workers after 30 seconds instead of 60 seconds (the default)
timeout 30
stderr_path "/var/www/fake/shared/log/unicorn.stderr.log"
stdout_path "/var/www/fake/shared/log/unicorn.stdout.log"
# combine REE with "preload_app true" for memory savings
# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
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!
old_pid = "#{server.config[:pid]}.oldbin"
if File.exists?(old_pid) && server.pid != old_pid
begin
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
Process.kill(sig, File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
end
end
end
after_fork do |server, worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment