Skip to content

Commit 6a49e55

Browse files
committed
Try to forward on sigint and sigterm to the gunicorn instance
1 parent d2140fa commit 6a49e55

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

entrypoint.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
#! /bin/bash
1+
#!/bin/bash
22

33
# The entrypoint.sh script is executed when the container is started.
44
# It is the perfect time to install the dependencies from the bound volume, run the migrations, and start the server.
55
# We'll use the docker-compose file that references this container to set an environment variable that will be used to determine if we should run the production or development server.
66

7+
# Trap SIGINT and SIGTERM signals and forward them to the child process
8+
trap 'kill -SIGINT $PID' SIGINT
9+
trap 'kill -SIGTERM $PID' SIGTERM
10+
711
# Install dependencies
812
poetry config virtualenvs.create false
913
poetry install --no-interaction --no-ansi --no-root
@@ -13,7 +17,13 @@ poetry run python manage.py migrate --no-input
1317

1418
# Start server
1519
if [ "$DJANGO_DEBUG" = "True" ]; then
16-
poetry run python manage.py runserver 0.0.0.0:8000
20+
poetry run python manage.py runserver 0.0.0.0:8000 &
1721
else
18-
poetry run gunicorn api.wsgi:application --bind 0.0.0.0:8000
22+
poetry run gunicorn api.wsgi:application --bind 0.0.0.0:8000 &
1923
fi
24+
25+
# Get the PID of the background process
26+
PID=$!
27+
28+
# Wait for the background process to finish
29+
wait $PID

0 commit comments

Comments
 (0)