worker_processes <%= node[:unicorn][:worker_processes] %> user "<%= @deploy[:user]%>" working_directory "<%= @deploy[:deploy_to]%>/current" listen "<%= @deploy[:deploy_to]%>/shared/sockets/unicorn.sock", :backlog => <%= node[:unicorn][:backlog] %>, :tcp_nodelay => <%= node[:unicorn][:tcp_nodelay] %>, :tcp_nopush => <%= node[:unicorn][:tcp_nopush] %>, :tries => <%= node[:unicorn][:tries] %>, :delay => <%= node[:unicorn][:delay] %>, :accept_filter => <%= node[:unicorn][:accept_filter].inspect %> timeout <%= node[:unicorn][:timeout] %> pid "<%= @deploy[:deploy_to]%>/shared/pids/unicorn.pid" stderr_path "<%= @deploy[:deploy_to]%>/shared/log/unicorn.stderr.log" stdout_path "<%= @deploy[:deploy_to]%>/shared/log/unicorn.stdout.log" <% @environment.each do |key, value| %> ENV['<%= key %>'] = "<%= value %>" <% end %> preload_app <%= node[:unicorn][:preload_app] %> GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=) # ensure Unicorn doesn't use a stale Gemfile when restarting # more info: https://willj.net/2011/08/02/fixing-the-gemfile-not-found-bundlergemfilenotfound-error/ before_exec do |server| ENV['BUNDLE_GEMFILE'] = "<%= @deploy[:deploy_to]%>/current/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 # Before forking, kill the master process that belongs to the .oldbin PID. # This enables 0 downtime deploys. old_pid = "<%= @deploy[:deploy_to]%>/shared/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 # someone else did our job for us 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 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