diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/unicorn.rb | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb index 44d1b6d..2f86de2 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -159,7 +159,7 @@ module Unicorn # are trapped. See trap_deferred @rd_sig, @wr_sig = IO.pipe unless (@rd_sig && @wr_sig) @rd_sig.nonblock = @wr_sig.nonblock = true - ready = mode = nil + mode = nil respawn = true QUEUE_SIGS.each { |sig| trap_deferred(sig) } @@ -173,6 +173,7 @@ module Unicorn when nil murder_lazy_workers spawn_missing_workers if respawn + master_sleep when 'QUIT' # graceful shutdown break when 'TERM', 'INT' # immediate shutdown @@ -206,18 +207,6 @@ module Unicorn else logger.error "master process in unknown mode: #{mode}" end - reap_all_workers - - ready = begin - IO.select([@rd_sig], nil, nil, 1) or next - rescue Errno::EINTR # next - end - ready[0] && ready[0][0] or next - begin - @rd_sig.sysread(1) - rescue Errno::EAGAIN, Errno::EINTR - # spurious wakeup? ignore it - end end rescue Errno::EINTR retry @@ -265,6 +254,17 @@ module Unicorn end end + # wait for a signal hander to wake us up and then consume the pipe + # Wake up every second anyways to run murder_lazy_workers + def master_sleep + begin + ready = IO.select([@rd_sig], nil, nil, 1) + ready && ready[0] && ready[0][0] or return + loop { @rd_sig.sysread(Const::CHUNK_SIZE) } + rescue Errno::EAGAIN, Errno::EINTR + end + end + def awaken_master begin @wr_sig.syswrite('.') # wakeup master process from IO.select |