From 6a49e550a707a443126b8d1676623e4d19e63a53 Mon Sep 17 00:00:00 2001 From: Jack Wilburn Date: Tue, 17 Dec 2024 11:28:36 -0700 Subject: [PATCH] Try to forward on sigint and sigterm to the gunicorn instance --- entrypoint.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 947bf56..a898c46 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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 @@ -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