production.rb 779 B

123456789101112131415161718192021222324252627282930313233
  1. app_path = "/home/you/app/current"
  2. worker_processes 2
  3. preload_app true
  4. timeout 180
  5. listen '/home/you/app/shared/pids/unicorn.socket'
  6. working_directory app_path
  7. rails_env = ENV['RAILS_ENV'] || 'production'
  8. # Log everything to one file
  9. stderr_path "log/unicorn.log"
  10. stdout_path "log/unicorn.log"
  11. # Set master PID location
  12. pid '/home/you/app/shared/pids/unicorn.pid'
  13. before_fork do |server, worker|
  14. ActiveRecord::Base.connection.disconnect!
  15. old_pid = "#{server.config[:pid]}.oldbin"
  16. if File.exists?(old_pid) && server.pid != old_pid
  17. begin
  18. Process.kill("QUIT", File.read(old_pid).to_i)
  19. rescue Errno::ENOENT, Errno::ESRCH
  20. # someone else did our job for us
  21. end
  22. end
  23. end
  24. after_fork do |server, worker|
  25. ActiveRecord::Base.establish_connection
  26. end