25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wait_db.py 457 B

12345678910111213141516171819
  1. #!/usr/bin/env python
  2. import socket
  3. import time
  4. import os
  5. host = os.environ.get('DATABASE_HOST', 'db')
  6. port = int(os.environ.get('DATABASE_PORT', '5432'))
  7. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  8. timeout = 15
  9. while timeout != 0:
  10. try:
  11. s.connect((host, port))
  12. s.close()
  13. break
  14. except socket.error as ex:
  15. timeout -= 1
  16. print('wait for db to start... (%s sec remaining)' % timeout)
  17. time.sleep(1)