-
-
Save jwieringa/43f7b28f18a7cbfa3ec9f8be613e793e to your computer and use it in GitHub Desktop.
A ruby script that will wait for a port to be connectable on a host, normally used to check if another Docker container has booted up
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "socket" | |
require "uri" | |
if ENV["DATABASE_URL"] | |
url = URI.parse ENV["DATABASE_URL"] | |
puts "Waiting for DB on #{url}..." | |
30.times do | |
begin | |
TCPSocket.new(url.host, url.port || 5432) | |
puts "Success!" | |
exit 0 | |
rescue => e | |
print "." | |
end | |
sleep 1 | |
end | |
exit 1 | |
else | |
STDERR.puts "No DATABASE_URL env var is set, skipping" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment