-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
87 lines (74 loc) · 1.39 KB
/
start.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
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env bash
set -e
DEBUG_MODE=false
Q_CLUSTER=false
PORT=""
usage() {
echo "Unrecognised option: -$OPTARG" >&2
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " -h Display this help message"
echo " -d Run server in debug mode"
echo " -w Start work scheduler"
}
migrations() {
echo "Checking and starting migrations"
python manage.py makemigrations
python manage.py migrate
}
cluster() {
echo "Starting qcluster"
python manage.py qcluster &
}
collect_static() {
echo 'Collecting static files...'
python manage.py collectstatic --no-input
}
start_dev_server() {
python manage.py runserver "0.0.0.0:$PORT"
}
start_prod_server() {
gunicorn "$APP_NAME.wsgi:application" \
--bind "0.0.0.0:$GUNICORN_PORT" \
--workers "$GUNICORN_WORKERS" \
--timeout "$GUNICORN_TIMEOUT" \
--log-level "$GUNICORN_LOG_LEVEL"
}
start_service() {
migrations
if $Q_CLUSTER; then
cluster
fi
echo "Starting server"
if $DEBUG_MODE; then
collect_static
start_dev_server
else
start_prod_server
fi
}
while getopts ":wd:h" opt; do
case ${opt} in
w)
Q_CLUSTER=true
;;
d)
DEBUG_MODE=true
PORT="$OPTARG"
;;
h)
usage
exit 0
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
\?)
usage
exit 1
;;
esac
done
shift $((OPTIND -1))
start_service