if [[ $@ == *"gunicorn"* || $@ == *"runserver"* ]]; then
if [[ -f $MANAGE ]]; then
- $BINDIR/wait_on_postgres.py
+ $BINDIR/wait_for_db.py
if [[ $? == 0 ]]; then
$MANAGE migrate --noinput
$MANAGE collectstatic --noinput
--- /dev/null
+#!/usr/bin/env python
+import os
+import psycopg2
+import time
+
+dbname = os.environ.get("DATABASE_NAME", ""),
+user = os.environ.get("DATABASE_USER", ""),
+password = os.environ.get("DATABASE_PASSWORD", ""),
+host = os.environ.get("DATABASE_HOST", "postgres"),
+port = int(os.environ.get("DATABASE_PORT", "5432"))
+
+attempts = 0
+max_attempts = 20
+
+while True:
+ try:
+ conn = psycopg2.connect(dbname=dbname, user=user, password=password, host=host, port=port)
+ # If we reach here, we're done
+ print("Connected to database {}".format(host))
+ sys.exit(0)
+ except Exception as e:
+ attempts += 1
+ if attempts > max_attempts:
+ print("Unable to connect to database")
+ print(e)
+ sys.exit(1)
+
+ time.sleep(3)
+
+
+
+++ /dev/null
-#!/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)
- entrypoint.sh
- setsite.py
- setadmin.py
- - wait_on_postgres.py
+ - wait_for_db.py
SECRET_KEY = os.environ.get("SECRET_KEY", "")
NEVERCACHE_KEY = os.environ.get("NEVERCACHE_KEY", "")
-ALLOWED_HOSTS = os.environ.get("ALLOWED_HOSTS", "")
+ALLOWED_HOSTS = os.environ.get("ALLOWED_HOSTS", "['*']")
DATABASES = {
"default": {
# Not used with sqlite3.
"PASSWORD": os.environ.get("DATABASE_PASSWORD", ""),
# Set to empty string for localhost. Not used with sqlite3.
- "HOST": os.environ.get("DATABASE_HOST", ""),
+ "HOST": os.environ.get("DATABASE_HOST", "postgres"),
# Set to empty string for default. Not used with sqlite3.
- "PORT": os.environ.get("DATABASE_PORT", "")
+ "PORT": os.environ.get("DATABASE_PORT", "5432")
}
}