Files
ubicloud/bin/production_check
Jeremy Evans 70f17c14cd Run bin/production check on port 8081
That way it doesn't break if you are currently running puma on
the default port of 8080.
2024-12-24 10:30:06 -08:00

61 lines
1.2 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", "-p", "8081") 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