Skip to content

Commit 6455e92

Browse files
authored
Merge pull request #1589 from maykinmedia/2997-uwsgi-process-management
[#2997] More resilient uWSGI process/worker management
2 parents fb1edff + 4748b20 commit 6455e92

File tree

1 file changed

+53
-21
lines changed

1 file changed

+53
-21
lines changed

bin/docker_start.sh

+53-21
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,61 @@ ${SCRIPTPATH}/wait_for_db.sh
1212

1313
# fixtures_dir=${FIXTURES_DIR:-/app/fixtures}
1414

15-
uwsgi_port=${UWSGI_PORT:-8000}
16-
uwsgi_processes=${UWSGI_PROCESSES:-4}
17-
uwsgi_threads=${UWSGI_THREADS:-8}
18-
uwsgi_http_timeout=${UWSGI_HTTP_TIMEOUT:-120}
19-
2015
# Apply database migrations
2116
>&2 echo "Apply database migrations"
2217
python src/manage.py migrate
2318

24-
# Start server
19+
##
20+
# uWSGI settings
21+
##
22+
23+
# --- Basic Application Configuration
24+
export UWSGI_MODULE="open_inwoner.wsgi"
25+
export UWSGI_CHDIR="src"
26+
export UWSGI_STATIC_MAP="/static=/app/static /media=/app/media"
27+
28+
# --- Process Management
29+
export UWSGI_MASTER=true
30+
export UWSGI_PROCESSES=${UWSGI_PROCESSES:-4}
31+
export UWSGI_THREADS=${UWSGI_THREADS:-8}
32+
33+
# Shutdown gracefully on SIGTERM (common with supervisord and k8s)
34+
export UWSGI_DIE_ON_TERM=true
35+
36+
# We're not hosting multiple apps, so no isolation required
37+
export UWSGI_SINGLE_INTERPRETER=true
38+
39+
# Enable Python threading
40+
export UWSGI_ENABLE_THREADS=true
41+
42+
# --- HTTP Server Settings
43+
export UWSGI_HTTP=${UWSGI_PORT:-8000}
44+
export UWSGI_HTTP_TIMEOUT=${UWSGI_HTTP_TIMEOUT:-120}
45+
export UWSGI_HTTP_KEEPALIVE=true
46+
47+
# --- Request Handling
48+
# Buffer size for POST requests
49+
export UWSGI_POST_BUFFERING=8192
50+
51+
# Internal buffer size
52+
export UWSGI_BUFFER_SIZE=65535
53+
54+
# --- Worker Lifecycle
55+
# Make UWSGI_MAX_REQUESTS explicitly opt-in
56+
if [ -n "${UWSGI_MAX_REQUESTS+x}" ]; then
57+
if [ "$UWSGI_MAX_REQUESTS" -gt 1 ] 2>/dev/null; then
58+
export UWSGI_MAX_REQUESTS
59+
else
60+
echo "Warning: UWSGI_MAX_REQUESTS must be greater than 1. The variable will be unset."
61+
unset UWSGI_MAX_REQUESTS
62+
fi
63+
else
64+
unset UWSGI_MAX_REQUESTS
65+
fi
66+
67+
# Hard-kill requests after 60 seconds
68+
export UWSGI_HARAKIRI=${UWSGI_HARAKIRI:-60}
69+
70+
# Start Server
2571
>&2 echo "Starting server"
26-
exec uwsgi \
27-
--die-on-term \
28-
--http :$uwsgi_port \
29-
--http-keepalive \
30-
--http-timeout $uwsgi_http_timeout \
31-
--module open_inwoner.wsgi \
32-
--static-map /static=/app/static \
33-
--static-map /media=/app/media \
34-
--chdir src \
35-
--enable-threads \
36-
--processes $uwsgi_processes \
37-
--threads $uwsgi_threads \
38-
--post-buffering=8192 \
39-
--buffer-size=65535
40-
# processes & threads are needed for concurrency without nginx sitting inbetween
72+
exec uwsgi --show-config --strict

0 commit comments

Comments
 (0)