From: Lorin Hochstein Date: Tue, 24 Jan 2017 06:29:20 +0000 (-0800) Subject: add wait_on_postgres.py X-Git-Url: https://git.halfball.org/?a=commitdiff_plain;h=0dbce8ec668bc8a82eff525283afca93574f64e4;p=ansiblebook.git add wait_on_postgres.py --- diff --git a/ch13/ansible/roles/mezzanine/files/wait_on_postgres.py b/ch13/ansible/roles/mezzanine/files/wait_on_postgres.py new file mode 100644 index 0000000..4c7b953 --- /dev/null +++ b/ch13/ansible/roles/mezzanine/files/wait_on_postgres.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# Code copied from: https://github.com/ansible/django-gulp-nginx/ +# + +import sys +import socket +import time + +if __name__ == '__main__': + + postgres_is_alive = False + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + tries = 0 + print ("Waiting on postgresql to start...") + while not postgres_is_alive and tries < 20: + tries += 1 + try: + s.connect(('postgresql', 5432)) + except socket.error: + time.sleep(3) + else: + postgres_is_alive = True + + if postgres_is_alive: + print ("Postgresql started!") + sys.exit(0) + else: + print ("Unable to reach postgresql on port 5432") + sys.exit(1)