unicorn.rb 1.0 KB

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