lib/consul/async/process_handler.rb in consul-templaterb-1.27.2 vs lib/consul/async/process_handler.rb in consul-templaterb-1.28.0
- old
+ new
@@ -5,30 +5,36 @@
end
# Handle the full lifecycle of a process and allows to forward
# Posix signals to child process when needed.
class ProcessHandler
- attr_reader :command, :sig_reload, :sig_term, :pid, :exit_status
+ attr_reader :command, :sig_reload, :sig_term, :pid, :exit_status, :last_signal_sent, :reload_scheduled
+ attr_writer :reload_scheduled
def initialize(command, sig_reload: 'HUP', sig_term: 'TERM')
raise 'empty sig_term is not supported' unless sig_term
@command = command
@sig_reload = sig_reload
@sig_term = sig_term
@pid = nil
@exit_status = nil
+ @last_signal_sent = Time.now
+ @reload_scheduled = false
end
def start
return pid unless pid.nil?
@pid = Process.spawn(command)
+ @last_signal_sent = Time.now
end
def reload
return if sig_reload.nil?
+ @last_signal_sent = Time.now
warn "Sending SIG #{sig_reload} to #{pid}..."
+ @reload_scheduled = false
begin
Process.kill(sig_reload, pid)
rescue Errno::ESRCH => e
warn "*** Process #{pid} has already been killed: #{e.inspect}"
raise e