Skip to content

Instantly share code, notes, and snippets.

@frank184
Created March 30, 2017 23:19
Show Gist options
  • Save frank184/fb81301b543187a2502ecd9887a3096a to your computer and use it in GitHub Desktop.
Save frank184/fb81301b543187a2502ecd9887a3096a to your computer and use it in GitHub Desktop.
Wait for DB
require 'socket'
def try_connection
TCPSocket.new(ENV['DB_HOST'], 3306)
rescue Errno::ECONNREFUSED
false
else
true
end
until try_connection
puts "Waiting for database..."
sleep 1
end
puts "Database is running!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment