lib/rexec/daemon/controller.rb in rexec-1.6.1 vs lib/rexec/daemon/controller.rb in rexec-1.6.2

- old
+ new

@@ -87,36 +87,15 @@ $stderr.reopen $stdout $stderr.sync = true begin - error = nil + daemon.run - main = Thread.new do - begin - daemon.run - rescue - error = $! - end - end - trap("INT") do - begin - daemon.shutdown - main.exit - rescue - error = $! - end + daemon.shutdown end - - trap("TERM") do - exit! - end - - main.join - - raise error if error rescue $stderr.puts "=== Daemon Exception Backtrace @ #{Time.now.to_s} ===" $stderr.puts "#{$!.class}: #{$!.message}" $!.backtrace.each { |at| $stderr.puts at } $stderr.puts "=== Daemon Crashed ===" @@ -182,23 +161,23 @@ unless ProcessFile.running(daemon) puts "Pid #{pid} is not running. Has daemon crashed?".color(:red) return end - pid = ProcessFile.recall(daemon) - Process.kill("INT", pid) + pgid = -Process.getpgid(pid) + Process.kill("INT", pgid) sleep 0.1 sleep 1 if ProcessFile.running(daemon) # Kill/Term loop - if the daemon didn't die easily, shoot # it a few more times. attempts = 5 while ProcessFile.running(daemon) and attempts > 0 sig = (attempts >= 2) ? "KILL" : "TERM" - puts "Sending #{sig} to pid #{pid}...".color(:red) - Process.kill(sig, pid) + puts "Sending #{sig} to process group #{pgid}...".color(:red) + Process.kill(sig, pgid) attempts -= 1 sleep 1 end