worker_processes <%= fetch(:unicorn_worker_processes) %> timeout <%= fetch(:unicorn_timeout) %> listen "<%= fetch(:unicorn_sock_file) %>" pid "<%= fetch(:unicorn_pid_file) %>" stderr_path "<%= fetch(:unicorn_error_log_file) %>" stdout_path "<%= fetch(:unicorn_log_file) %>" preload_app true before_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! old_pid = "#{ server.config[:pid] }.oldbin" unless old_pid == server.pid begin Process.kill :QUIT, File.read(old_pid).to_i rescue Errno::ENOENT, Errno::ESRCH end end end after_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end