From b1c6d188d4c03dd85143565b1318f583bf8cc0c7 Mon Sep 17 00:00:00 2001 From: pacnpal <183241239+pacnpal@users.noreply.github.com> Date: Tue, 28 Jan 2025 14:50:00 -0500 Subject: [PATCH] feat(docker): add entrypoint script for graceful shutdown and application start --- Dockerfile | 8 ++++++-- docker-entrypoint.sh | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index f4531f5..6e68f7e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,10 @@ COPY . . # Install the package in editable mode RUN pip install -e . +# Copy and set up entrypoint script +COPY docker-entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/docker-entrypoint.sh + # Create rules backup directory with proper permissions RUN mkdir -p /app/rules_backup && \ chmod 777 /app/rules_backup @@ -36,5 +40,5 @@ EXPOSE 8000 # Volume for persisting rules backups VOLUME ["/app/rules_backup"] -# Command to run the application -CMD ["python", "-m", "simpleguardhome.main"] \ No newline at end of file +# Set entrypoint +ENTRYPOINT ["docker-entrypoint.sh"] \ No newline at end of file diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..97533fb --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -e + +# Function to handle termination signals +handle_term() { + echo "Received SIGTERM/SIGINT, shutting down gracefully..." + kill -TERM "$child" + wait "$child" + exit 0 +} + +# Set up signal handlers +trap handle_term SIGTERM SIGINT + +# Start the application +echo "Starting SimpleGuardHome server..." +python -m simpleguardhome.main & + +# Store child PID +child=$! + +# Wait for process to complete +wait "$child" \ No newline at end of file