forked from tl-its-umich-edu/canvas-app-explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_backend.sh
executable file
·75 lines (61 loc) · 2.03 KB
/
start_backend.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Case insenstive match
shopt -s nocaseglob
echo "$DJANGO_SETTINGS_MODULE"
if [ -z "${GUNICORN_WORKERS}" ]; then
GUNICORN_WORKERS=4
fi
if [ -z "${GUNICORN_PORT}" ]; then
GUNICORN_PORT=5000
fi
if [ -z "${GUNICORN_TIMEOUT}" ]; then
GUNICORN_TIMEOUT=120
fi
if [ -z "${DB_HOST}" ]; then
DB_HOST=canvas_app_explorer_mysql
fi
if [ -z "${DB_PORT}" ]; then
DB_PORT=3306
fi
# To have a more static default secret key, this should still be defined
if [ -z "${DJANGO_SECRET_KEY}" ]; then
export DJANGO_SECRET_KEY=`python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'`
echo "DJANGO_SECRET_KEY not set, using random value"
fi
if [ "${GUNICORN_RELOAD}" ]; then
GUNICORN_RELOAD="--reload"
else
GUNICORN_RELOAD=
fi
# To have a more static default secret key, this should still be defined
if [ -z "${DJANGO_SECRET_KEY}" ]; then
export DJANGO_SECRET_KEY=`python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'`
echo "DJANGO_SECRET_KEY not set, using random value"
fi
echo "Waiting for DB ${DB_HOST}:${DB_PORT}"
while ! nc -z "${DB_HOST}" "${DB_PORT}"; do
sleep 1 # wait 1 second before check again
done
echo Running python startups
python manage.py migrate
echo "Setting domain of default site record"
# The value for LOCALHOST_PORT is set in docker-compose.yml
#if [ "${DOMAIN}" == "localhost" ]; then
# python manage.py site --domain="${DOMAIN}:${LOCALHOST_PORT}" --name="${DOMAIN}"
#else
# python manage.py site --domain="${DOMAIN}" --name="${DOMAIN}"
#fi
if [ "${DEBUGPY_ENABLE:-"false"}" == "false" ]; then
echo "Starting Gunicorn for production"
else
echo "Starting Gunicorn for DEBUGPY debugging"
# Workers need to be set to 1 for DEBUGPY
GUNICORN_WORKERS=1
GUNICORN_RELOAD="--reload"
GUNICORN_TIMEOUT=0
fi
exec gunicorn backend.wsgi:application \
--bind 0.0.0.0:${GUNICORN_PORT} \
--workers="${GUNICORN_WORKERS}" \
--timeout="${GUNICORN_TIMEOUT}" \
${GUNICORN_RELOAD}