lib/rflow/daemon_process.rb in rflow-1.1.0 vs lib/rflow/daemon_process.rb in rflow-1.2.0
- old
+ new
@@ -109,13 +109,19 @@
$0 = @name
end
def handle_signals
['SIGTERM', 'SIGINT', 'SIGQUIT', 'SIGCHLD'].each do |signal|
- trap_signal(signal) do
+ trap_signal(signal) do |return_code|
+ exit_status = if signal == 'SIGCHLD'
+ pid, status = Process.wait2
+ status.exitstatus
+ else
+ 0
+ end
shutdown! signal
- exit! 0
+ exit! exit_status
end
end
trap_signal 'SIGUSR1' do
RFlow.logger.reopen
@@ -134,15 +140,16 @@
end
end
def trap_signal(signal)
# Log4r and traps don't mix, so we need to put it in another thread
+ return_code = $?
context = clone_logging_context
Signal.trap signal do
Thread.new do
apply_logging_context context
- yield
+ yield return_code
end.join
end
end
def signal_successful_start
@@ -153,10 +160,14 @@
end
def signal_subprocesses(signal)
subprocesses.reject {|p| p.pid.nil? }.each do |p|
RFlow.logger.info "Signaling #{p.name} with #{signal}"
- Process.kill(signal, p.pid)
+ begin
+ Process.kill(signal, p.pid)
+ rescue Errno::ESRCH
+ # process already died and was waited for, ignore
+ end
end
end
def write_pid_file; @pid_file.write if @pid_file; end
def remove_pid_file; @pid_file.safe_unlink if @pid_file; end