lib/navy/captain.rb in navy-1.0.5 vs lib/navy/captain.rb in navy-1.0.6
- old
+ new
@@ -14,10 +14,13 @@
attr_accessor :label, :captain_pid, :timeout, :officer_count, :officer_job, :respawn_limit, :respawn_limit_seconds
attr_reader :admiral, :options
def initialize(admiral, label, config, options = {})
+ self.orig_stderr = $stderr.dup
+ self.orig_stdout = $stdout.dup
+
@options = options.dup
@options[:use_defaults] = true
@options[:config_file] = config
self.orders = Navy::Captain::Orders.new(self.class, @options)
@options.merge!(orders.set)
@@ -30,15 +33,16 @@
def ==(other_label)
@label == other_label
end
def start
- orders.give!(self, only: [ :stderr_path, :stdout_path ])
init_self_pipe!
QUEUE_SIGS.each do |sig|
trap(sig) do
- logger.debug "captain[#{label}] received #{sig}" if $DEBUG
+ if $DEBUG
+ logger.debug "captain[#{label}] received #{sig}"
+ end
SIG_QUEUE << sig
awaken_captain
end
end
trap(:CHLD) { awaken_captain }
@@ -185,9 +189,11 @@
before_fork.call(self, officer) if before_fork
if pid = fork
OFFICERS[pid] = officer
RESPAWNS[n] ||= []
RESPAWNS[n].push(Time.now)
+ officer.officer_pid = pid
+ post_fork.call(self, officer) if post_fork
else
after_fork.call(self, officer) if after_fork
officer.start
exit
end
\ No newline at end of file