lib/rflow/daemon_process.rb in rflow-1.2.0 vs lib/rflow/daemon_process.rb in rflow-1.3.0a1
- old
+ new
@@ -1,9 +1,11 @@
require 'rflow/pid_file'
class RFlow
class DaemonProcess
+ SIGINFO = 29
+
def initialize(name, role = name, options = {})
@name = name
@role = role
@pid_file = PIDFile.new(options[:pid_file_path]) if options[:pid_file_path]
end
@@ -90,33 +92,25 @@
end
end
def register_logging_context
# arrange for process's name to appear in log messages
- Log4r::NDC.clear
- Log4r::NDC.push @name
+ RFlow.logger.clear_logging_context
+ RFlow.logger.add_logging_context @name
end
- def clone_logging_context
- Log4r::NDC.clone_stack
- end
-
- def apply_logging_context(context)
- Log4r::NDC.inherit(context)
- end
-
def update_process_name
# set the visible process name to match the process's name
$0 = @name
end
def handle_signals
['SIGTERM', 'SIGINT', 'SIGQUIT', 'SIGCHLD'].each do |signal|
trap_signal(signal) do |return_code|
exit_status = if signal == 'SIGCHLD'
pid, status = Process.wait2
- status.exitstatus
+ status.exitstatus || 0
else
0
end
shutdown! signal
exit! exit_status
@@ -130,24 +124,29 @@
trap_signal 'SIGUSR2' do
RFlow.logger.toggle_log_level
signal_subprocesses 'SIGUSR2'
end
+
+ trap_signal SIGINFO do
+ RFlow.logger.dump_threads
+ # don't tell child processes to dump, too spammy
+ end
end
def unhandle_signals
- ['SIGTERM', 'SIGINT', 'SIGQUIT', 'SIGCHLD', 'SIGUSR1', 'SIGUSR2'].each do |signal|
+ ['SIGTERM', 'SIGINT', 'SIGQUIT', 'SIGCHLD', 'SIGUSR1', 'SIGUSR2', SIGINFO].each do |signal|
Signal.trap signal, 'DEFAULT'
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
+ context = RFlow.logger.clone_logging_context
Signal.trap signal do
Thread.new do
- apply_logging_context context
+ RFlow.logger.apply_logging_context context
yield return_code
end.join
end
end