mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:25:35 +08:00
DEV: make bin/ember-cli -u
terminate unicorn when ember-cli fails (#18172)
This commit is contained in:
parent
54b8500881
commit
d262775c3e
|
@ -15,6 +15,12 @@ PROXY =
|
||||||
"http://#{HOSTNAME}:#{PORT}"
|
"http://#{HOSTNAME}:#{PORT}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def process_running?(pid)
|
||||||
|
!!Process.kill(0, pid)
|
||||||
|
rescue Errno::ESRCH
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
command =
|
command =
|
||||||
if ARGV.include?("--test")
|
if ARGV.include?("--test")
|
||||||
"test"
|
"test"
|
||||||
|
@ -58,11 +64,13 @@ end
|
||||||
if ARGV.include?("-u") || ARGV.include?("--unicorn")
|
if ARGV.include?("-u") || ARGV.include?("--unicorn")
|
||||||
unicorn_env = { "DISCOURSE_PORT" => ENV["DISCOURSE_PORT"] || "4200" }
|
unicorn_env = { "DISCOURSE_PORT" => ENV["DISCOURSE_PORT"] || "4200" }
|
||||||
unicorn_pid = spawn(unicorn_env, __dir__ + "/unicorn")
|
unicorn_pid = spawn(unicorn_env, __dir__ + "/unicorn")
|
||||||
|
ember_cli_pid = nil
|
||||||
|
|
||||||
Thread.new do
|
Thread.new do
|
||||||
require 'open3'
|
require 'open3'
|
||||||
Open3.popen2e(yarn_env, "yarn", *args.to_a.flatten) do |i, oe, t|
|
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|
|
oe.each do |line|
|
||||||
if line.include?("\e[32m200\e") || line.include?("\e[36m304\e[0m") || line.include?("POST /message-bus")
|
if line.include?("\e[32m200\e") || line.include?("\e[36m304\e[0m") || line.include?("POST /message-bus")
|
||||||
# skip 200s and 304s and message bus
|
# skip 200s and 304s and message bus
|
||||||
|
@ -71,6 +79,10 @@ if ARGV.include?("-u") || ARGV.include?("--unicorn")
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
trap("SIGINT") do
|
trap("SIGINT") do
|
||||||
|
@ -79,6 +91,11 @@ if ARGV.include?("-u") || ARGV.include?("--unicorn")
|
||||||
end
|
end
|
||||||
|
|
||||||
Process.wait(unicorn_pid)
|
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
|
else
|
||||||
exec(yarn_env, "yarn", *args.to_a.flatten)
|
exec(yarn_env, "yarn", *args.to_a.flatten)
|
||||||
end
|
end
|
||||||
|
|
|
@ -107,6 +107,10 @@ if dev_mode
|
||||||
restart = true
|
restart = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Signal.trap("TERM") do
|
||||||
|
Process.kill('TERM', pid)
|
||||||
|
end
|
||||||
|
|
||||||
while !done
|
while !done
|
||||||
sleep 1
|
sleep 1
|
||||||
done = Process.waitpid(pid, Process::WNOHANG)
|
done = Process.waitpid(pid, Process::WNOHANG)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user