Add #stop method on Foreman::Engine for stopping certain named processes
This will make embedding foreman "nicer" since the embedder can then stop a specific process (e.g. turning off a service for an integration fail-over test)
This commit is contained in:
1 parent
69216b4c5e
commit
c705b5fbef
2 files changed
+20
-1
No files matched your search
+17
-1
@@ -39,6 +39,22 @@ class Foreman::Engine
|
|||||||
spawn_processes
|
spawn_processes
|
||||||
watch_for_output
|
watch_for_output
|
||||||
watch_for_termination
|
watch_for_termination
|
||||||
|
terminate_gracefully
|
||||||
|
end
|
||||||
|
|
||||||
|
def stop(name)
|
||||||
|
running_processes.each do |pid, process|
|
||||||
|
next unless process.name.start_with? name
|
||||||
|
|
||||||
|
process.kill 'SIGTERM'
|
||||||
|
process = running_processes.delete(pid)
|
||||||
|
Timeout.timeout(5) do
|
||||||
|
begin
|
||||||
|
Process.waitpid(pid)
|
||||||
|
rescue Errno::ECHILD
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def port_for(process, num, base_port=nil)
|
def port_for(process, num, base_port=nil)
|
||||||
@@ -91,6 +107,7 @@ private ######################################################################
|
|||||||
rescue Timeout::Error
|
rescue Timeout::Error
|
||||||
info "sending SIGKILL to all processes"
|
info "sending SIGKILL to all processes"
|
||||||
kill_all "SIGKILL"
|
kill_all "SIGKILL"
|
||||||
|
rescue Errno::ECHILD
|
||||||
end
|
end
|
||||||
|
|
||||||
def poll_readers
|
def poll_readers
|
||||||
@@ -123,7 +140,6 @@ private ######################################################################
|
|||||||
pid, status = Process.wait2
|
pid, status = Process.wait2
|
||||||
process = running_processes.delete(pid)
|
process = running_processes.delete(pid)
|
||||||
info "process terminated", process.name
|
info "process terminated", process.name
|
||||||
terminate_gracefully
|
|
||||||
rescue Errno::ECHILD
|
rescue Errno::ECHILD
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ describe "Foreman::Engine", :fakefs do
|
|||||||
mock.instance_of(Foreman::Process).run_process(Dir.pwd, "./bravo", is_a(IO))
|
mock.instance_of(Foreman::Process).run_process(Dir.pwd, "./bravo", is_a(IO))
|
||||||
mock(subject).watch_for_output
|
mock(subject).watch_for_output
|
||||||
mock(subject).watch_for_termination
|
mock(subject).watch_for_termination
|
||||||
|
mock(subject).terminate_gracefully
|
||||||
subject.start
|
subject.start
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ describe "Foreman::Engine", :fakefs do
|
|||||||
mock.instance_of(Foreman::Process).run_process(Dir.pwd, "./bravo", is_a(IO)).never
|
mock.instance_of(Foreman::Process).run_process(Dir.pwd, "./bravo", is_a(IO)).never
|
||||||
mock(engine).watch_for_output
|
mock(engine).watch_for_output
|
||||||
mock(engine).watch_for_termination
|
mock(engine).watch_for_termination
|
||||||
|
mock(engine).terminate_gracefully
|
||||||
engine.start
|
engine.start
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -109,6 +111,7 @@ describe "Foreman::Engine", :fakefs do
|
|||||||
it "should spawn" do
|
it "should spawn" do
|
||||||
stub(subject).watch_for_output
|
stub(subject).watch_for_output
|
||||||
stub(subject).watch_for_termination
|
stub(subject).watch_for_termination
|
||||||
|
stub(subject).terminate_gracefully
|
||||||
subject.start
|
subject.start
|
||||||
Process.waitall
|
Process.waitall
|
||||||
mock(subject).info(/started with pid \d+/, "utf8.1", anything)
|
mock(subject).info(/started with pid \d+/, "utf8.1", anything)
|
||||||
|
|||||||
Reference in new issue
Block a user