Add after_worker_exit configuration option
commit2af91a1fef70d6546ee03760011c170a082db667
authorJeremy Evans <code@jeremyevans.net>
Sat, 18 Feb 2017 00:12:33 +0000 (17 16:12 -0800)
committerEric Wong <e@80x24.org>
Tue, 21 Feb 2017 21:27:27 +0000 (21 21:27 +0000)
treec41faa65f4786cc0312e64ebef6759d162a785b0
parent2c6aa5878d052abb77c6d119e1c2e2110118a244
Add after_worker_exit configuration option

This option is executed in the master process following all
worker process exits.  It is most useful in the case where
the worker process crashes the ruby interpreter, as the worker
process may not be able to send error notifications
appropriately.

For example, let's say you have a specific request that crashes a
worker process, which you expect to be due to a improperly
programmed C extension. By modifying your worker to save request
related data in a temporary file and using this option, you can get
a record of what request is crashing the application, which will
make debugging easier.

Example:

after_worker_exit do |server, worker, status|
  server.logger.info "worker #{status.success? ? 'exit' : 'crash'}: #{status}"

  file = "request.#{status.pid}.txt"
  if File.exist?(file)
    do_something_with(File.read(file)) unless status.success?
    File.delete(file)
  end
end
lib/unicorn/configurator.rb
lib/unicorn/http_server.rb