2016-02-03 17:11:23 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
2017-09-28 10:15:50 +00:00
|
|
|
function wait_for_broker {
|
2017-02-09 15:46:06 +00:00
|
|
|
set +e
|
2017-02-09 17:03:16 +00:00
|
|
|
for try in {1..60} ; do
|
2017-03-08 15:45:07 +00:00
|
|
|
python -c "from kombu import Connection; x=Connection('$CELERY_BROKER_URL', timeout=1); x.connect()" && break
|
2017-02-09 17:03:16 +00:00
|
|
|
echo "Waiting for celery broker to respond..."
|
2017-02-09 15:46:06 +00:00
|
|
|
sleep 1
|
|
|
|
done
|
2017-09-28 10:15:50 +00:00
|
|
|
}
|
2016-02-03 17:11:23 +00:00
|
|
|
|
2017-09-28 10:15:50 +00:00
|
|
|
function wait_for_database {
|
2017-02-09 15:46:06 +00:00
|
|
|
set +e
|
2017-02-09 17:03:16 +00:00
|
|
|
for try in {1..60} ; do
|
2017-03-08 15:45:07 +00:00
|
|
|
python -c "from django.db import connection; connection.connect()" && break
|
2017-02-09 17:03:16 +00:00
|
|
|
echo "Waiting for database to respond..."
|
2017-02-09 15:46:06 +00:00
|
|
|
sleep 1
|
|
|
|
done
|
2017-09-28 10:15:50 +00:00
|
|
|
}
|
2016-02-03 17:11:23 +00:00
|
|
|
|
2017-09-28 10:15:50 +00:00
|
|
|
function wait_for_migrations {
|
2017-02-09 21:37:07 +00:00
|
|
|
set +e
|
|
|
|
for try in {1..60} ; do
|
2017-03-08 15:45:07 +00:00
|
|
|
# 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
|
2017-02-09 21:37:07 +00:00
|
|
|
echo "Waiting for database migrations to be run..."
|
|
|
|
sleep 1
|
|
|
|
done
|
2017-09-28 10:15:50 +00:00
|
|
|
}
|
2017-02-09 21:37:07 +00:00
|
|
|
|
2017-02-09 15:46:06 +00:00
|
|
|
|
|
|
|
wait_for_broker
|
|
|
|
wait_for_database
|
|
|
|
|
2017-02-09 16:20:34 +00:00
|
|
|
if [ -z "$SKIP_INIT" ]; then
|
|
|
|
/code/bin/build-app
|
|
|
|
fi
|
|
|
|
|
2017-02-09 21:37:07 +00:00
|
|
|
if [ -n "$WAIT_FOR_MIGRATIONS" ]; then
|
|
|
|
wait_for_migrations
|
|
|
|
fi
|
|
|
|
|
2017-02-09 15:46:06 +00:00
|
|
|
exec "$@"
|