From 0057c878003b41efb3a53529409f16f9073f0934 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 26 Mar 2009 22:28:42 -0700 Subject: Don't allow failed log rotation to to break app 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. --- lib/unicorn.rb | 16 +++++++++++----- 1 file 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 -- cgit v1.2.3-24-ge0c7