diff --git a/api/scripts/run-docker.sh b/api/scripts/run-docker.sh index 88ae045c98f5..2f299ea805af 100755 --- a/api/scripts/run-docker.sh +++ b/api/scripts/run-docker.sh @@ -1,16 +1,16 @@ #!/bin/sh set -e -function waitfordb() { +waitfordb() { if [ -z "${SKIP_WAIT_FOR_DB}" ]; then python manage.py waitfordb "$@" fi } -function migrate () { +migrate () { waitfordb && python manage.py migrate && python manage.py createcachetable } -function serve() { +serve() { # configuration parameters for statsd. Docs can be found here: # https://docs.gunicorn.org/en/stable/instrumentation.html export STATSD_PORT=${STATSD_PORT:-8125} @@ -31,9 +31,9 @@ function serve() { ${STATSD_HOST:+--statsd-prefix $STATSD_PREFIX} \ app.wsgi } -function run_task_processor() { +run_task_processor() { waitfordb --waitfor 30 --migrations - if [[ -n "$ANALYTICS_DATABASE_URL" || -n "$DJANGO_DB_NAME_ANALYTICS" ]]; then + if [ -n "$ANALYTICS_DATABASE_URL" ] || [ -n "$DJANGO_DB_NAME_ANALYTICS" ]; then waitfordb --waitfor 30 --migrations --database analytics fi RUN_BY_PROCESSOR=1 exec python manage.py runprocessor \ @@ -42,29 +42,31 @@ function run_task_processor() { --numthreads ${TASK_PROCESSOR_NUM_THREADS:-5} \ --queuepopsize ${TASK_PROCESSOR_QUEUE_POP_SIZE:-10} } -function migrate_analytics_db(){ +migrate_analytics_db(){ # if `$ANALYTICS_DATABASE_URL` or DJANGO_DB_NAME_ANALYTICS is set # run the migration command - if [[ -z "$ANALYTICS_DATABASE_URL" && -z "$DJANGO_DB_NAME_ANALYTICS" ]]; then + if [ -z "$ANALYTICS_DATABASE_URL" ] && [ -z "$DJANGO_DB_NAME_ANALYTICS" ]; then return 0 fi python manage.py migrate --database analytics } -function bootstrap(){ +bootstrap(){ python manage.py bootstrap } -function default(){ +default(){ python manage.py "$@" } -if [ "$1" == "migrate" ]; then +set -x + +if [ "$1" = "migrate" ]; then migrate migrate_analytics_db -elif [ "$1" == "serve" ]; then +elif [ "$1" = "serve" ]; then serve -elif [ "$1" == "run-task-processor" ]; then +elif [ "$1" = "run-task-processor" ]; then run_task_processor -elif [ "$1" == "migrate-and-serve" ]; then +elif [ "$1" = "migrate-and-serve" ]; then migrate migrate_analytics_db bootstrap