-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_server.sh
executable file
·132 lines (123 loc) · 2.95 KB
/
run_server.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env bash
PARAMS=""
while (("$#")); do
case "$1" in
-m | --make-migrations)
MAKE_MIGRATIONS=1
shift
;;
-l | --load-fixtures)
LOAD_FIXTURES=1
shift
;;
-r | --run-mode)
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
RUN_MODE=$2
shift 2
case "$RUN_MODE" in
local-dev | local-ssl | docker)
;;
*)
echo "InvalidRunMode: -r | --run-mode <local-dev | local-ssl | docker>"
exit 1
;;
esac
else
echo "Error: Argument for $1 is missing" >&2
exit 1
fi
;;
-* | --*=) # unsupported flags
echo "Error: Unsupported flag $1" >&2
exit 1
;;
*) # preserve positional arguments
PARAMS="$PARAMS $1"
shift
;;
esac
done
# set positional arguments in their proper place
eval set -- "$PARAMS"
# ensure a valid run-mode was set
case "$RUN_MODE" in
local-dev | local-ssl | docker)
;;
*)
echo "InvalidRunMode: -r | --run-mode <local-dev | local-ssl | docker>"
exit 1
;;
esac
# make app migrations
if [[ "${MAKE_MIGRATIONS}" -eq 1 ]]; then
echo "### MAKE_MIGRATIONS = True ###"
APPS_LIST=(
"mixins"
"users"
"profiles"
"resources"
"projects"
"experiment_files"
"experiments"
"operations"
"credentials"
"user_messages"
"user_requests"
)
else
echo "### MAKE_MIGRATIONS = False ###"
APPS_LIST=()
fi
# load fixtures
if [[ "${LOAD_FIXTURES}" -eq 1 ]]; then
echo "### LOAD_FIXTURES = True ###"
FIXTURES_LIST=(
"aerpaw_roles"
"resources"
"experiment_files"
"operations"
"profiles"
"users"
"credentials"
"projects"
"experiments"
"user_messages"
"user_requests"
)
else
echo "### LOAD_FIXTURES = False ###"
FIXTURES_LIST=()
fi
# migrations files
for app in "${APPS_LIST[@]}"; do
python manage.py makemigrations $app
done
python manage.py makemigrations
python manage.py showmigrations
python manage.py migrate
# load fixtures
for fixture in "${FIXTURES_LIST[@]}"; do
python manage.py loaddata $fixture
done
# static files
python manage.py collectstatic --noinput
# run mode
case "${RUN_MODE}" in
local-dev)
echo "local-dev"
python manage.py runserver 0.0.0.0:8000
;;
local-ssl)
echo "local-ssl"
uwsgi --uid "${UWSGI_UID:-1000}" --gid "${UWSGI_GID:-1000}" --virtualenv ./venv --ini aerpaw-portal.ini
;;
docker)
echo "docker"
uwsgi --uid "${UWSGI_UID:-1000}" --gid "${UWSGI_GID:-1000}" --virtualenv ./.venv --ini aerpaw-portal.ini
;;
*)
echo "ModeRequired: -r | --run-mode <local-dev | local-ssl | docker>"
exit 1
;;
esac
exit 0