Commit 4d0a9ccf authored by Stefan Bienert's avatar Stefan Bienert
Browse files

Let Django wait for the database to be up and running.

parent c6ccdcfe
......@@ -37,7 +37,6 @@ db_conn = connections['default']
try:
db_conn.cursor()
except OperationalError:
sys.stderr.write("Database not yet available.\n")
sys.exit(1)
except:
raise
......@@ -49,7 +48,7 @@ END
# exit immediately on commands with a non-zero exit status.
set -e
# wait for Redis and set it up
# wait for Redis
>&2 echo "Wait for Redis"
until redis_ready; do
>&2 echo "Redis is not ready yet - sleep 1s"
......@@ -57,6 +56,14 @@ until redis_ready; do
done
>&2 echo "Redis up and running"
# wait for the database
>&2 echo "Wait for database"
until postgres_ready; do
>&2 echo "Database is not ready yet - sleep 1s"
sleep 1
done
>&2 echo "Database up and running"
# Make sure the database is set up
>&2 echo "Assure database is set up with tables"
python3 manage.py makemigrations
......@@ -70,6 +77,8 @@ python3 manage.py collectstatic --noinput
python3 manage.py shell << END
from django.contrib.auth.models import User
try:
User.objects.get(username='admin')
except User.DoesNotExist:
User.objects.create_superuser('admin', 'ad@m.in', 'admin')
except Exception as dexc:
if str(dexc) == 'UNIQUE constraint failed: auth_user.username':
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment