Skip to content

Commit

Permalink
Try to forward on sigint and sigterm to the gunicorn instance
Browse files Browse the repository at this point in the history
  • Loading branch information
JackWilb committed Dec 17, 2024
1 parent d2140fa commit 6a49e55
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#! /bin/bash
#!/bin/bash

# The entrypoint.sh script is executed when the container is started.
# It is the perfect time to install the dependencies from the bound volume, run the migrations, and start the server.
# 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.

# Trap SIGINT and SIGTERM signals and forward them to the child process
trap 'kill -SIGINT $PID' SIGINT
trap 'kill -SIGTERM $PID' SIGTERM

# Install dependencies
poetry config virtualenvs.create false
poetry install --no-interaction --no-ansi --no-root
Expand All @@ -13,7 +17,13 @@ poetry run python manage.py migrate --no-input

# Start server
if [ "$DJANGO_DEBUG" = "True" ]; then
poetry run python manage.py runserver 0.0.0.0:8000
poetry run python manage.py runserver 0.0.0.0:8000 &
else
poetry run gunicorn api.wsgi:application --bind 0.0.0.0:8000
poetry run gunicorn api.wsgi:application --bind 0.0.0.0:8000 &
fi

# Get the PID of the background process
PID=$!

# Wait for the background process to finish
wait $PID

0 comments on commit 6a49e55

Please sign in to comment.