feat: add sigterm support (#2472)

This commit is contained in:
Meier Lukas
2025-03-02 20:28:11 +01:00
committed by GitHub
parent 7dfb108a56
commit a5e0e8c129
3 changed files with 28 additions and 7 deletions

View File

@@ -1 +1,2 @@
docker run -p 7575:7575 homarr:latest
:: Please do not run this command in production. It is only for local testing.
docker run -p 7575:7575 -e SECRET_ENCRYPTION_KEY=0000000000000000000000000000000000000000000000000000000000000000 homarr:latest

View File

@@ -19,7 +19,7 @@ if [ "${PUID}" != "0" ] || [ "${PGID}" != "0" ]; then
fi
if [ "${PUID}" != "0" ]; then
su-exec $PUID:$PGID "$@"
exec su-exec $PUID:$PGID "$@"
else
exec "$@"
fi

View File

@@ -19,17 +19,37 @@ export AUTH_SECRET=$(openssl rand -base64 32)
# 2. Create the nginx configuration file from the template
# 3. Start the nginx server
envsubst '${HOSTNAME}' < /etc/nginx/templates/nginx.conf > /etc/nginx/nginx.conf
# Start services in the background and store their PIDs
nginx -g 'daemon off;' &
NGINX_PID=$!
# Start Redis
redis-server /app/redis.conf &
REDIS_PID=$!
# Run the tasks backend
node apps/tasks/tasks.cjs &
TASKS_PID=$!
node apps/websocket/wssServer.cjs &
WSS_PID=$!
# Run the nextjs server
node apps/nextjs/server.js & PID=$!
node apps/nextjs/server.js &
NEXTJS_PID=$!
wait $PID
# Function to handle SIGTERM and shut down services
terminate() {
echo "Received SIGTERM. Shutting down..."
kill -TERM $NGINX_PID $TASKS_PID $WSS_PID $NEXTJS_PID 2>/dev/null
wait
# kill redis-server last because of logging of other services
kill -TERM $REDIS_PID 2>/dev/null
wait
echo "Shutdown complete."
exit 0
}
# When SIGTERM (docker stop <container>) / SIGINT (ctrl+c) is received, run the terminate function
trap terminate TERM INT
# Wait for all processes
wait $NEXTJS_PID
terminate