diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-03-19 18:50:39 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-03-19 20:19:05 -0700 |
commit | e9be891dc851015eaf592d3c64caff77398f1246 (patch) | |
tree | b62f7b58f99258c1423b1caea9a553579c5a5bf2 /lib | |
parent | c01c8ccae6a4b500d0aebd385c10f4567d9b0fd3 (diff) | |
download | unicorn-e9be891dc851015eaf592d3c64caff77398f1246.tar.gz |
This will only be enabled if we're daemonized and "real" WINCH signals cannot be generated by resizing the terminal. This is to avoid confusing developers who run in the foreground of a terminal. Additionally document procedures for reexecuting a running binary.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/unicorn.rb | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb index 7b7c4bb..9245f53 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -161,6 +161,7 @@ module Unicorn @rd_sig, @wr_sig = IO.pipe unless (@rd_sig && @wr_sig) @rd_sig.nonblock = @wr_sig.nonblock = true ready = mode = nil + respawn = true QUEUE_SIGS.each { |sig| trap_deferred(sig) } trap('CHLD') { |sig_nr| awaken_master } @@ -172,7 +173,7 @@ module Unicorn case (mode = @sig_queue.shift) when nil murder_lazy_workers - spawn_missing_workers + spawn_missing_workers if respawn when 'QUIT' # graceful shutdown break when 'TERM', 'INT' # immediate shutdown @@ -183,7 +184,16 @@ module Unicorn Unicorn::Util.reopen_logs when 'USR2' # exec binary, stay alive in case something went wrong reexec + when 'WINCH' + if ppid == 1 || getpgrp != $$ + respawn = false + logger.info "gracefully stopping all workers" + kill_each_worker('QUIT') + else + logger.info "SIGWINCH ignored because we're not daemonized" + end when 'HUP' + respawn = true if @config.config_file load_config! redo # immediate reaping since we may have QUIT workers @@ -239,7 +249,8 @@ module Unicorn private # list of signals we care about and trap in master. - QUEUE_SIGS = %w(QUIT INT TERM USR1 USR2 HUP).map { |x| x.freeze }.freeze + QUEUE_SIGS = + %w(WINCH QUIT INT TERM USR1 USR2 HUP).map { |x| x.freeze }.freeze # defer a signal for later processing in #join (master process) def trap_deferred(signal) @@ -271,6 +282,7 @@ module Unicorn logger.error "reaped exec()-ed PID:#{pid} status=#{$?.exitstatus}" @reexec_pid = 0 self.pid = @pid.chomp('.oldbin') if @pid + $0 = "unicorn master" else worker = @workers.delete(pid) worker.tempfile.close rescue nil @@ -324,6 +336,7 @@ module Unicorn @before_exec.call(self) if @before_exec exec(*cmd) end + $0 = "unicorn master (old)" end # forcibly terminate all workers that haven't checked in in @timeout |