lib/navy/captain.rb in navy-1.1.1 vs lib/navy/captain.rb in navy-1.1.2

- old
+ new

@@ -10,11 +10,11 @@ SIG_QUEUE = [] # list of signals we care about and trap in admiral. QUEUE_SIGS = [ :WINCH, :QUIT, :INT, :TERM, :USR1, :USR2, :HUP, :TTIN, :TTOU ] - attr_accessor :label, :captain_pid, :officer_count, :officer_job + attr_accessor :label, :captain_pid, :officer_count, :officer_job, :officer_fire_and_forget attr_reader :admiral, :options def initialize(admiral, label, config, options = {}) self.orig_stderr = $stderr.dup self.orig_stdout = $stdout.dup @@ -122,11 +122,11 @@ # Terminates all captains, but does not exit admiral process def stop(graceful = true) before_stop.call(self, graceful) if before_stop limit = Time.now + patience until OFFICERS.empty? || (n = Time.now) > limit - kill_each_officer(graceful ? :QUIT : :TERM) + kill_each_officer(graceful ? :QUIT : :TERM, officer_fire_and_forget) sleep(0.1) reap_all_officers end if n and n > limit logger.debug "captain=#{label} patience exceeded by #{n - limit} seconds (limit #{patience} seconds)" if $DEBUG @@ -219,19 +219,23 @@ } end # delivers a signal to a officer and fails gracefully if the officer # is no longer running. - def kill_officer(signal, opid) + def kill_officer(signal, opid, detach = false) logger.debug "captain[#{label}] sending #{signal} to #{opid}" if $DEBUG Process.kill(signal, opid) + if detach + Process.detach(opid) + officer = OFFICERS.delete(opid) rescue nil + end rescue Errno::ESRCH officer = OFFICERS.delete(opid) rescue nil end # delivers a signal to each officer - def kill_each_officer(signal) - OFFICERS.keys.each { |opid| kill_officer(signal, opid) } + def kill_each_officer(signal, detach = false) + OFFICERS.keys.each { |opid| kill_officer(signal, opid, detach) } end def init_self_pipe! SELF_PIPE.each { |io| io.close rescue nil } SELF_PIPE.replace(Kgio::Pipe.new) \ No newline at end of file