Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pbansal
Test-Docker
Commits
4d0a9ccf
Commit
4d0a9ccf
authored
Aug 12, 2019
by
Stefan Bienert
Browse files
Let Django wait for the database to be up and running.
parent
c6ccdcfe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Docker/cathapi/entrypoint.sh
View file @
4d0a9ccf
...
...
@@ -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':
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment