Skip to content

A platform for community discussion. Free, open, simple.

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

David Taylord262775c3e35
diff --git a/bin/ember-cli b/bin/ember-cli
index 55f771aa281..7f5decb36fc 100755
--- a/bin/ember-cli
+++ b/bin/ember-cli
@@ -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
diff --git a/bin/unicorn b/bin/unicorn
index 6f6e169313b..2d076feff4b 100755
--- a/bin/unicorn
+++ b/bin/unicorn
@@ -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)