diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-03-26 22:28:42 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-03-26 22:28:42 -0700 |
commit | 0057c878003b41efb3a53529409f16f9073f0934 (patch) | |
tree | bf9c812d0506b59246874b6645cb87cb9810158e | |
parent | 63209531722311896ac448d9170adb0766fa3eff (diff) | |
download | unicorn-0057c878003b41efb3a53529409f16f9073f0934.tar.gz |
In case there are permissions problems that cause log rotation to fail, we trap the error and defer death until the current request finishes running.
-rw-r--r-- | lib/unicorn.rb | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb index e36cb1e..5bf7519 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -406,11 +406,6 @@ module Unicorn @sig_queue.clear QUEUE_SIGS.each { |sig| trap(sig, 'IGNORE') } trap('CHLD', 'DEFAULT') - trap('USR1') do - @logger.info "worker=#{worker.nr} rotating logs..." - Unicorn::Util.reopen_logs - @logger.info "worker=#{worker.nr} done rotating logs" - end $0 = "unicorn worker[#{worker.nr}]" @rd_sig.close if @rd_sig @@ -440,6 +435,17 @@ module Unicorn alive = false @listeners.each { |sock| sock.close rescue nil } # break IO.select end + trap('USR1') do + begin + @logger.info "worker=#{worker.nr} rotating logs..." + Unicorn::Util.reopen_logs + @logger.info "worker=#{worker.nr} done rotating logs" + rescue Object => err + @logger.error "error rotating logs: #{err.inspect}" + @logger.error "gracefully restarting worker=#{worker.nr} PID:#$$" + Process.kill('QUIT', $$) + end + end while alive && @master_pid == Process.ppid # we're a goner in @timeout seconds anyways if tempfile.chmod |