-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathuwsgi.run
219 lines (182 loc) · 5.24 KB
/
uwsgi.run
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/bin/bash
trap "exit 130" SIGINT
trap "exit 137" SIGKILL
trap "exit 143" SIGTERM
generate_config () {
cd /opt
if [[ ! -f ./config.py ]]
then
if [[ -z ${EMAIL} ]]
then
echo "Admin email is required"
exit 1
else
EMAIL="--email ${EMAIL}"
fi
if [[ ! -z ${SERVER_BASE_URL} ]]
then
SERVER_BASE_URL="--base_url ${SERVER_BASE_URL}"
else
SERVER_BASE_URL=""
fi
if [[ ! -z "${HONEYMAP_URL}" ]]
then
HONEYMAP_URL="--honeymap_url ${HONEYMAP_URL}"
else
HONEYMAP_URL=""
fi
MAIL_SERVER="--mail_server ${MAIL_SERVER:-127.0.0.1}"
MAIL_PORT="--mail_port ${MAIL_PORT:-25}"
if [[ "${MAIL_TLS}" == "y" ]]
then
MAIL_TLS="--mail_tls"
else
MAIL_TLS=""
fi
if [[ "${MAIL_SSL}" == "y" ]]
then
MAIL_SSL="--mail_ssl"
else
MAIL_SSL=""
fi
if [[ ! -z "${MAIL_USER}" ]]
then
MAIL_USER="--mail_user ${MAIL_USER}"
else
MAIL_USER=""
fi
if [[ ! -z "${MAIL_PASSWORD}" ]]
then
MAIL_PASSWORD="--mail_pass ${MAIL_PASSWORD}"
else
MAIL_PASSWORD=""
fi
if [[ ! -z "${DEFAULT_MAIL_SENDER}" ]]
then
DEFAULT_MAIL_SENDER="--mail_sender ${DEFAULT_MAIL_SENDER}"
else
DEFAULT_MAIL_SENDER=""
fi
if [[ ! -z "${LOG_FILE_PATH}" ]]
then
LOG_FILE_PATH="--log_file_path ${LOG_FILE_PATH}"
else
LOG_FILE_PATH=""
fi
if [[ ! -z "${DEBUG}" ]]
then
DEBUG="--debug ${DEBUG}"
else
DEBUG=""
fi
if [[ ! -z "${MONGODB_HOST}" ]]
then
MONGODB_HOST="--mongo_host ${MONGODB_HOST}"
else
MONGODB_HOST=""
fi
if [[ -z ${MONGODB_PORT} ]]
then
echo "MongoDB port is required"
exit 1
else
MONGODB_PORT="--mongo_port ${MONGODB_PORT}"
fi
if [[ ! -z "${HPFEEDS_HOST}" ]]
then
HPFEEDS_HOST="--hpfeeds_host ${HPFEEDS_HOST}"
else
HPFEEDS_HOST=""
fi
HPFEEDS_PORT="--hpfeeds_port ${HPFEEDS_PORT:-10000}"
if [[ ! -z ${SUPERUSER_EMAIL} ]]
then
SUPERUSER_EMAIL="--email ${SUPERUSER_EMAIL}"
else
SUPERUSER_EMAIL=""
fi
if [[ ! -z ${SUPERUSER_PASSWORD} ]]
then
SUPERUSER_PASSWORD="--password ${SUPERUSER_PASSWORD}"
else
SUPERUSER_PASSWORD=""
fi
if [[ ! -z ${SECRET_KEY} ]]
then
SECRET_KEY="--secret_key ${SECRET_KEY}"
else
SECRET_KEY=""
fi
if [[ ! -z ${DEPLOY_KEY} ]]
then
DEPLOY_KEY="--deploy_key ${DEPLOY_KEY}"
else
DEPLOY_KEY=""
fi
python3 generateconfig.py unattended ${EMAIL} \
${SERVER_BASE_URL} \
${HONEYMAP_URL} \
${MAIL_SERVER} \
${MAIL_PORT} \
${MAIL_SSL} \
${MAIL_TLS} \
${MAIL_USER} \
${MAIL_PASSWORD} \
${DEFAULT_MAIL_SENDER} \
${LOG_FILE_PATH} \
${MONGODB_HOST} \
${MONGODB_PORT} \
${HPFEEDS_HOST} \
${HPFEEDS_PORT} \
${SUPERUSER_EMAIL} \
${SUPERUSER_PASSWORD} \
${SECRET_KEY} \
${DEPLOY_KEY}
# Generate config file for hpfeeds broker
cd {{ hpfeeds_dir }}/hpfeeds/broker
python3 generateconfig.py unattended ${MONGODB_HOST} ${MONGODB_PORT}
fi
cd /opt
if [[ "${1}" == "--no-db-init" ]]
then
echo 'null'
return
else
python3 initdatabase.py
echo $!
return $?
fi
}
make_logdir () {
cd /opt
local log_file_path=$(awk '/LOG_FILE_PATH/ {print $3}' /opt/config.py |sed "s/'//g")
local logdir=$(awk -F/ 'BEGIN{FS=OFS="/"}{NF--; print}' <<< ${log_file_path})
mkdir -p ${logdir}
touch ${log_file_path}
chown -R www-data.root ${log_file_path}
}
generate_nginx_config () {
cd /opt
export custom_url_from_generate_nginx_func=$(awk '/SERVER_BASE_URL/ {print $3}' /opt/config.py | sed "s/'//g")
python3 generate_nginx_standalone.py --server-base-url ${custom_url_from_generate_nginx_func} --output-file-nginx /etc/nginx/sites-available/default -f
}
main () {
generate_config
make_logdir
generate_nginx_config
local custom_url_path=$(python3 -c "from urllib.parse import urlparse; import os; result=urlparse(os.environ['custom_url_from_generate_nginx_func']); print(result.path.rstrip('/'))")
echo "Found custom_url_path=${custom_url_path}"
cd /opt
# if custom_url_path isn't null, there's a custom path in SERVER_BASE_URL, so use it as a mount point
# otherwise, mount at default root route as normal
if [[ -z ${custom_url_path} ]]
then
custom_url_path="/"
fi
exec uwsgi --socket /tmp/uwsgi.sock \
--module mhn:mhn \
--chmod-socket=666 \
--buffer-size 04960 \
--manage-script-name --mount ${custom_url_path}=mhn:mhn
}
main "${@}"