# -*- ruby -*- # Sample verbose configuration file for Unicorn # # See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete # documentation. # 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 <%= unicorn_worker_processes %> # Help ensure your application will always spawn in the symlinked # "current" directory that Capistrano sets up. working_directory "<%= current_path %>" # listen on Unix domain socket and let nginx proxy listen "<%= shared_path %>/pids/unicorn.sock" # nuke workers after 30 seconds instead of 60 seconds (the default) timeout 30 # Location of the pidfile. Should not be changed unless you # know what you are doing. pid "<%= shared_path %>/pids/unicorn.pid" # By default, the Unicorn logger will write to stderr. # Additionally, some applications/frameworks log to stderr or stdout, # so prevent them from going to /dev/null when daemonized here: stderr_path "<%= shared_path %>/log/unicorn.stderr.log" stdout_path "<%= shared_path %>/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 if GC.respond_to?(:copy_on_write_friendly=) GC.copy_on_write_friendly = true end # this is required to make bundler use the correct Gemfile in case unicorn is # upgraded via USR2. otherwise the symlink will be expanded and old Gemfiles # may be used after upgrade. before_exec do |server| ENV["BUNDLE_GEMFILE"] = "<%= current_path %>/Gemfile" end 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 if defined?(ActiveRecord::Base) ActiveRecord::Base.connection.disconnect! end if defined?(DataObjects::Pooling) DataObjects::Pooling.pools.each do |pool| pool.dispose end end # This allows a new master process to incrementally # phase out the old master process with SIGTTOU to avoid a # thundering herd (especially in the "preload_app false" case) # when doing a transparent upgrade. The last worker spawned # will then kill off the old master process with a SIGQUIT. old_pid = "<%= shared_path %>/pids/unicorn.pid.oldbin" if old_pid != server.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| # the following is *required* for Rails + "preload_app true", if defined?(ActiveRecord::Base) ActiveRecord::Base.establish_connection end if defined?(Rails) if defined?(ActiveSupport::Cache::DalliStore) if Rails.cache.is_a?(ActiveSupport::Cache::DalliStore) Rails.cache.reset end end end # 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