Files
ubicloud/bin/production_check
Jeremy Evans a848403ca6 Add bin/production_check for checking app loads in production
This file starts puma, and checks for correct loading or for
failure.  It returns 0 on success and 1 on failure, printing
the error to stderr in the failure case.

Run this before the control plane tests in CI.  I've tested
that this file catches the production issue in my deployment
this morning.
2024-11-07 09:43:04 -08:00

58 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: 3)
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
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
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