forked from arachnys/cabot
-
Notifications
You must be signed in to change notification settings - Fork 2
/
docker-entrypoint.sh
41 lines (34 loc) · 1018 Bytes
/
docker-entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
set -e
function wait_for_broker {
set +e
for try in {1..60} ; do
python -c "from kombu import Connection; x=Connection('$CELERY_BROKER_URL', timeout=1); x.connect()" && break
echo "Waiting for celery broker to respond..."
sleep 60
done
}
function wait_for_database {
set +e
for try in {1..60} ; do
python -c "from django.db import connection; connection.connect()" && break
echo "Waiting for database to respond..."
sleep 60
done
}
function wait_for_migrations {
set +e
for try in {1..60} ; do
# Kind of ugly but not sure if there's another way to determine if migrations haven't run.
# showmigrations -p returns a checkbox list of migrations, empty checkboxes mean they haven't been run
python manage.py showmigrations -p | grep "\[ \]" &> /dev/null || break
echo "Waiting for database migrations to be run..."
sleep 30
done
}
wait_for_broker
wait_for_database
if [ -n "$WAIT_FOR_MIGRATIONS" ]; then
wait_for_migrations
fi
exec "$@"