Skip to content

Instantly share code, notes, and snippets.

@eduardodeoh
Created November 2, 2012 20:38
Show Gist options
  • Save eduardodeoh/4004176 to your computer and use it in GitHub Desktop.
Save eduardodeoh/4004176 to your computer and use it in GitHub Desktop.
Unicorn Configuration Example
#APP DIRECTORY
app_dir="/var/www/rails_apps/todolist/current"
# Use at least one worker per core if you're on a dedicated server,
# more will usually help for _short_ waits on databases/caches.
worker_processes 1
# Help ensure your application will always spawn in the symlinked
# "current" directory that Capistrano sets up.
working_directory app_dir
# Load app into the master before forking workers for super-fast
# # worker spawn times
preload_app true
# listen on both a Unix domain socket and a TCP port,
# we use a shorter backlog for quicker failover when busy
listen "#{app_dir}/tmp/sockets/unicorn.socket", :backlog => 64
#listen 127.0.0.1:8080, :tcp_nopush => true
# nuke workers after 30 seconds instead of 60 seconds (the default)
timeout 30
# feel free to point this anywhere accessible on the filesystem
pid "#{app_dir}/tmp/pids/unicorn.pid"
# By default, the Unicorn logger will write to stderr.
# Additionally, ome applications/frameworks log to stderr or stdout,
# so prevent them from going to /dev/null when daemonized here:
stderr_path "#{app_dir}/log/unicorn.stderr.log"
stdout_path "#{app_dir}/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
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment