Skip to content

Instantly share code, notes, and snippets.

@aiwilliams
Created November 20, 2010 16:32
Show Gist options
  • Save aiwilliams/707942 to your computer and use it in GitHub Desktop.
Save aiwilliams/707942 to your computer and use it in GitHub Desktop.
unicorn config for Rails dev with nginx
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
# documentation.
application_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
preload_app true
worker_processes 1
working_directory application_root
listen File.join(application_root, "tmp/sockets/unicorn.sock"), :backlog => 64
pid File.join(application_root, "tmp/pids/unicorn.pid")
#stderr_path File.join(application_root, "log/unicorn.stderr.log")
#stdout_path File.join(application_root, "log/unicorn.stdout.log")
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
before_fork do |server, worker|
# the following is highly recomended for Rails + "preload_app true"
# as there's no need for the master process to hold a connection
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
# per-process listener ports for debugging/admin/migrations
# addr = "127.0.0.1:#{9293 + worker.nr}"
# server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
# the following is *required* for Rails + "preload_app true",
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
# if preload_app is true, then you may also want to check and
# restart any other shared sockets/descriptors such as Memcached,
# and Redis. TokyoCabinet file handles are safe to reuse
# between any number of forked children (assuming your kernel
# correctly implements pread()/pwrite() system calls)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment