Created
August 23, 2020 18:59
-
-
Save gagansh7171/e0fd72b9dcb1d1f8cc83e86382207618 to your computer and use it in GitHub Desktop.
Check DB before manage.py
This file contains 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
import socket | |
import time | |
import argparse | |
""" Check if port is open, avoid docker-compose race condition """ | |
parser = argparse.ArgumentParser(description='Check if port is open, avoid\ | |
docker-compose race condition') | |
parser.add_argument('--service-name', required=True) | |
parser.add_argument('--ip', required=True) | |
parser.add_argument('--port', required=True) | |
args = parser.parse_args() | |
# Get arguments | |
service_name = str(args.service_name) | |
port = int(args.port) | |
ip = str(args.ip) | |
# Infinite loop | |
while True: | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
result = sock.connect_ex((ip, port)) | |
if result == 0: | |
print("{0} port is open! Bye!".format(service_name)) | |
break | |
else: | |
print("{0} port is not open! I'll check it soon!".format(service_name)) | |
time.sleep(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment