From c2e51916201f4f29a72e21320b38181ee1eaa697 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 4 May 2009 02:07:40 +0000 Subject: Instant shutdown signals really mean instant shutdown Use SIGQUIT if you're going to be nice and do graceful shutdowns. Sometimes people run real applications on this server and SIGINT/SIGTERM get lost/trapped when Object is rescued and that is not good. Also make sure we break out of the loop properly when the master is dead. Testcases added for both SIGINT and dead master handling. --- lib/unicorn.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lib/unicorn.rb') diff --git a/lib/unicorn.rb b/lib/unicorn.rb index db25223..a539960 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -474,7 +474,7 @@ module Unicorn # closing anything we IO.select on will raise EBADF trap(:USR1) { nr = -65536; SELF_PIPE.first.close rescue nil } trap(:QUIT) { alive = nil; LISTENERS.each { |s| s.close rescue nil } } - [:TERM, :INT].each { |sig| trap(sig) { exit(0) } } # instant shutdown + [:TERM, :INT].each { |sig| trap(sig) { exit!(0) } } # instant shutdown @logger.info "worker=#{worker.nr} ready" while alive @@ -512,7 +512,7 @@ module Unicorn # and do a speculative accept_nonblock on every listener # before we sleep again in select(). if nr == 0 # (nr < 0) => reopen logs - master_pid == Process.ppid or exit(0) + master_pid == Process.ppid or return alive.chmod(nr += 1) begin # timeout used so we can detect parent death: @@ -524,8 +524,6 @@ module Unicorn nr < 0 or exit(alive ? 1 : 0) end end - rescue SignalException, SystemExit => e - raise e rescue Object => e if alive logger.error "Unhandled listen loop exception #{e.inspect}." -- cgit v1.2.3-24-ge0c7