DEV: make `bin/ember-cli -u` terminate unicorn when ember-cli fails (#18172)

This commit is contained in:
David Taylor 2022-09-02 22:51:51 +01:00 committed by GitHub
parent 54b8500881
commit d262775c3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -15,6 +15,12 @@ PROXY =
"http://#{HOSTNAME}:#{PORT}"
end
def process_running?(pid)
!!Process.kill(0, pid)
rescue Errno::ESRCH
false
end
command =
if ARGV.include?("--test")
"test"
@ -58,11 +64,13 @@ end
if ARGV.include?("-u") || ARGV.include?("--unicorn")
unicorn_env = { "DISCOURSE_PORT" => ENV["DISCOURSE_PORT"] || "4200" }
unicorn_pid = spawn(unicorn_env, __dir__ + "/unicorn")
ember_cli_pid = nil
Thread.new do
require 'open3'
Open3.popen2e(yarn_env, "yarn", *args.to_a.flatten) do |i, oe, t|
puts "Ember CLI running on PID: #{t.pid}"
ember_cli_pid = t.pid
puts "Ember CLI running on PID: #{ember_cli_pid}"
oe.each do |line|
if line.include?("\e[32m200\e") || line.include?("\e[36m304\e[0m") || line.include?("POST /message-bus")
# skip 200s and 304s and message bus
@ -71,6 +79,10 @@ if ARGV.include?("-u") || ARGV.include?("--unicorn")
end
end
end
if process_running?(unicorn_pid)
puts "[bin/ember-cli] ember-cli process stopped. Terminating unicorn."
Process.kill("TERM", unicorn_pid)
end
end
trap("SIGINT") do
@ -79,6 +91,11 @@ if ARGV.include?("-u") || ARGV.include?("--unicorn")
end
Process.wait(unicorn_pid)
if ember_cli_pid && process_running?(ember_cli_pid)
puts "[bin/ember-cli] unicorn process stopped. Terminating ember-cli."
Process.kill("TERM", ember_cli_pid)
end
else
exec(yarn_env, "yarn", *args.to_a.flatten)
end

View File

@ -107,6 +107,10 @@ if dev_mode
restart = true
end
Signal.trap("TERM") do
Process.kill('TERM', pid)
end
while !done
sleep 1
done = Process.waitpid(pid, Process::WNOHANG)