Files
ubicloud/bin/production_check
Jeremy Evans ff0ea5802a Print stdout lines in production_check
This can help determine what output was received, which may help
debugging timeouts.
2024-11-20 11:48:23 -08:00

61 lines
1.1 KiB
Ruby
Executable File

#!/usr/bin/env ruby
# frozen_string_literal: true
Dir.chdir(File.dirname(__dir__))
require "open3"
works = nil
error = +""
queue = Queue.new
Open3.popen3({"RACK_ENV" => "production"}, "bundle", "exec", "puma") do |stdin, stdout, stderr, wait_thr|
pid = wait_thr.pid
timer_thread = Thread.new do
queue.pop(timeout: 6)
if works.nil?
error = "Timeout"
Process.kill(:KILL, pid)
end
end
stdout_thread = Thread.new do
while (line = stdout.gets)
case line
when /\A\* Listening on /
works = true
puts line
queue.push(true)
Process.kill(:TERM, pid)
break
when /\A! Unable to load application: /
error << line
works = false
queue.push(true)
Process.kill(:TERM, pid)
break
else
puts line
end
end
end
stderr_thread = Thread.new do
err = stderr.read(1)
if !err.nil?
error << err << stderr.read_nonblock(100000)
works = false
queue.push(true)
Process.kill(:TERM, pid)
end
end
[stdout_thread, stderr_thread, timer_thread].map(&:join)
end
unless works
warn error
exit(1)
end