Compare commits

...
3 Commits
Author SHA1 Message Date
David Dollar fd234b8044 0.18.0 2011-06-03 01:32:14 -04:00
David Dollar f2f09554c8 correct shutdown signals
processes are sent SIGTERM followed 3 seconds later by SIGKILL
2011-06-03 01:31:51 -04:00
David Dollar 6c465b4ef1 remove debug print 2011-06-03 01:31:08 -04:00
6 changed files with 35 additions and 15 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
PATH PATH
remote: . remote: .
specs: specs:
foreman (0.17.0) foreman (0.18.0)
term-ansicolor (~> 1.0.5) term-ansicolor (~> 1.0.5)
thor (>= 0.13.6) thor (>= 0.13.6)
+2
View File
@@ -0,0 +1,2 @@
#!/usr/bin/env ruby
exec ARGV.join(" ")
+6
View File
@@ -1,5 +1,11 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
%w( SIGINT SIGTERM SIGHUP ).each do |signal|
trap(signal) do
puts "received #{signal} but i'm ignoring it!"
end
end
while true while true
puts "tick: #{ARGV.inspect} -- FOO:#{ENV["FOO"]}" puts "tick: #{ARGV.inspect} -- FOO:#{ENV["FOO"]}"
sleep 1 sleep 1
+25 -12
View File
@@ -3,6 +3,7 @@ require "foreman/process"
require "foreman/utils" require "foreman/utils"
require "pty" require "pty"
require "tempfile" require "tempfile"
require "timeout"
require "term/ansicolor" require "term/ansicolor"
require "fileutils" require "fileutils"
@@ -58,8 +59,8 @@ class Foreman::Engine
fork process, options, environment fork process, options, environment
end end
trap("TERM") { puts "SIGTERM received"; kill_all("TERM") } trap("TERM") { puts "SIGTERM received"; terminate_gracefully }
trap("INT") { puts "SIGINT received"; kill_all("TERM") } trap("INT") { puts "SIGINT received"; terminate_gracefully }
watch_for_termination watch_for_termination
end end
@@ -69,8 +70,8 @@ class Foreman::Engine
fork processes[name], options, environment fork processes[name], options, environment
trap("TERM") { puts "SIGTERM received"; kill_all("TERM") } trap("TERM") { puts "SIGTERM received"; terminate_gracefully }
trap("INT") { puts "SIGINT received"; kill_all("TERM") } trap("INT") { puts "SIGINT received"; terminate_gracefully }
watch_for_termination watch_for_termination
end end
@@ -107,12 +108,12 @@ private ######################################################################
def run(process) def run(process)
proctitle "ruby: foreman #{process.name}" proctitle "ruby: foreman #{process.name}"
trap("SIGINT", "IGNORE")
begin begin
Dir.chdir directory do Dir.chdir directory do
command = process.command PTY.spawn(runner, process.command) do |stdin, stdout, pid|
trap("SIGTERM") { Process.kill("SIGTERM", pid) }
PTY.spawn("#{process.command} 2>&1") do |stdin, stdout, pid|
until stdin.eof? until stdin.eof?
info stdin.gets, process info stdin.gets, process
end end
@@ -126,11 +127,9 @@ private ######################################################################
end end
end end
def kill_all(signal="TERM") def kill_all(signal="SIGTERM")
info "terminating"
running_processes.each do |pid, process| running_processes.each do |pid, process|
info "killing #{process.name} in pid #{pid}" Process.kill(signal, pid) rescue Errno::ESRCH
Process.kill(signal, pid)
end end
end end
@@ -179,8 +178,9 @@ private ######################################################################
pid, status = Process.wait2 pid, status = Process.wait2
process = running_processes.delete(pid) process = running_processes.delete(pid)
info "process terminated", process info "process terminated", process
terminate_gracefully
kill_all kill_all
Process.waitall rescue Errno::ECHILD
end end
def running_processes def running_processes
@@ -217,4 +217,17 @@ private ######################################################################
environment environment
end end
def runner
File.expand_path("../../../bin/foreman-runner", __FILE__)
end
def terminate_gracefully
info "sending SIGTERM to all processes"
kill_all "SIGTERM"
Timeout.timeout(3) { Process.waitall }
rescue Timeout::Error
info "sending SIGKILL to all processes"
kill_all "SIGKILL"
end
end end
+1 -1
View File
@@ -1,5 +1,5 @@
module Foreman module Foreman
VERSION = "0.17.0" VERSION = "0.18.0"
end end
-1
View File
@@ -13,7 +13,6 @@ describe Foreman::Export::Upstart do
it "exports to the filesystem" do it "exports to the filesystem" do
upstart.export("/tmp/init") upstart.export("/tmp/init")
p [:d, Dir["/tmp/init/**"]]
File.read("/tmp/init/app.conf").should == example_export_file("upstart/app.conf") File.read("/tmp/init/app.conf").should == example_export_file("upstart/app.conf")
File.read("/tmp/init/app-alpha.conf").should == example_export_file("upstart/app-alpha.conf") File.read("/tmp/init/app-alpha.conf").should == example_export_file("upstart/app-alpha.conf")