unicorn.rb 986 B

123456789101112131415161718192021222324252627
  1. worker_processes 4
  2. timeout 30
  3. stderr_path 'log/unicorn_error.log'
  4. stdout_path 'log/unicorn_access.log'
  5. pid 'tmp/pids/unicorn.pid'
  6. before_fork do |server, _worker|
  7. ##
  8. # When sent a USR2, Unicorn will suffix its pidfile with .oldbin and
  9. # immediately start loading up a new version of itself (loaded with a new
  10. # version of our app). When this new Unicorn is completely loaded
  11. # it will begin spawning workers. The first worker spawned will check to
  12. # see if an .oldbin pidfile exists. If so, this means we've just booted up
  13. # a new Unicorn and need to tell the old one that it can now die. To do so
  14. # we send it a QUIT.
  15. #
  16. # Using this method we get 0 downtime deploys.
  17. old_pid = 'tmp/pids/unicorn.pid.oldbin'
  18. if File.exist?(old_pid) && server.pid != old_pid
  19. begin
  20. Process.kill('QUIT', File.read(old_pid).to_i)
  21. rescue Errno::ENOENT, Errno::ESRCH
  22. logger.info 'Unicorn master already killed. Someone else did our job for us.'
  23. end
  24. end
  25. end