Skip to content

Instantly share code, notes, and snippets.

@davidcornu
Created May 3, 2012 02:44
Show Gist options
  • Save davidcornu/2582657 to your computer and use it in GitHub Desktop.
Save davidcornu/2582657 to your computer and use it in GitHub Desktop.
Unicorn Config
# Set user
user "deployer"
# Set production environment
ENV['RAILS_ENV'] = 'production'
# Set incoming port
listen 3000
# Set worker processes
worker_processes 2
# Reduce timeout from 60
timeout 30
# Optimize for copy on write
preload_app true
# Save the PID
pid "tmp/pids/unicorn.pid"
# Prevent shared resources due to forking
before_fork do |server, worker|
ActiveRecord::Base.connection.disconnect! if defined?(ActiveRecord::Base)
$redis.client.disconnect if defined?($redis)
# Kill the old process if it exists
old_pid = "tmp/pids/unicorn.pid.oldbin"
if File.exists?(old_pid) && server.pid != old_pid
begin
Process.kill("QUIT", File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
puts "Old master already quit"
end
end
end
after_fork do |server, worker|
ActiveRecord::Base.establish_connection if defined?(ActiveRecord::Base)
$redis.client.reconnect if defined?($redis)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment