Skip to content

Commit

Permalink
OBS-410: Add script for graceful gunicorn shutdown. (#3082)
Browse files Browse the repository at this point in the history
  • Loading branch information
smarnach authored Dec 9, 2024
1 parent bd596d6 commit b746214
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bin/run_web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
: "${PORT:=8000}"
: "${GUNICORN_WORKERS:=4}"
: "${GUNICORN_TIMEOUT:=600}"
: "${GUNICORN_GRACEFUL_TIMEOUT:=600}"

export PROCESS_NAME=webapp

Expand All @@ -20,8 +21,10 @@ else
echo "GUNICORN_TIMEOUT=${GUNICORN_TIMEOUT}"
echo "PORT=${PORT}"
${CMD_PREFIX} gunicorn \
--pid /tmp/gunicorn.pid \
--bind 0.0.0.0:"${PORT}" \
--timeout "${GUNICORN_TIMEOUT}" \
--graceful-timeout "${GUNICORN_GRACEFUL_TIMEOUT}" \
--workers "${GUNICORN_WORKERS}" \
--config=tecken/gunicornhooks.py \
--access-logfile - \
Expand Down
16 changes: 16 additions & 0 deletions bin/stop_gunicorn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Send the TERM signal to gunicorn to trigger a graceful shutdown, and wait for it to exit.

set -euo pipefail

pid=`cat /tmp/gunicorn.pid`

if [ -n "$pid" ]; then
echo "Sending TERM signal to gunicorn."
kill -TERM "$pid"
echo "Waiting for gunicorn to exit..."
while kill -0 $pid 2>/dev/null; do
sleep 1
done
fi

0 comments on commit b746214

Please sign in to comment.