Last active
April 25, 2019 21:42
-
-
Save diegogslomp/fee17c4a6e76ef8c41a35221c033c4fc to your computer and use it in GitHub Desktop.
Python script to wait db connection for docker-compose
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 python | |
import socket | |
import time | |
import os | |
if __name__ == '__main__': | |
port = int(os.environ["DB_PORT"]) # 5432 | |
host = os.environ["DB_HOST"] # db | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
while True: | |
try: | |
s.connect((host, port)) | |
s.close() | |
break | |
except socket.error as ex: | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment