From 162dfc6000dcc1246440460f57091853ce5edfd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Schm=C3=BCcker?= Date: Fri, 26 Jun 2026 18:26:14 +0200 Subject: [PATCH] fix dashboard exit on api failure --- build/package/dashboard-entrypoint.sh | 53 +++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/build/package/dashboard-entrypoint.sh b/build/package/dashboard-entrypoint.sh index 9da05a5894..6237b15d04 100644 --- a/build/package/dashboard-entrypoint.sh +++ b/build/package/dashboard-entrypoint.sh @@ -6,10 +6,12 @@ trap 'shutdown' SIGTERM SIGINT # Function to handle shutdown shutdown() { echo "Gracefully shutting down hatchet-api..." - kill -SIGTERM "$HATCHET_API_PID" + kill -SIGTERM "$HATCHET_API_PID" 2>/dev/null + kill -SIGTERM "$NGINX_PID" 2>/dev/null - # Wait for hatchet-api to exit - wait "$HATCHET_API_PID" + # Wait for child processes to exit + wait "$HATCHET_API_PID" 2>/dev/null + wait "$NGINX_PID" 2>/dev/null echo "Shutting down NGINX..." nginx -s quit @@ -18,9 +20,46 @@ shutdown() { exit 0 } -# Start hatchet-api with any passed command line arguments in the background -./hatchet-api "$@" & +HATCHET_API_STATUS_FILE="/tmp/hatchet-api-status-$$" +NGINX_STATUS_FILE="/tmp/nginx-status-$$" + +( + trap 'kill -SIGTERM "$HATCHET_API_CHILD_PID" 2>/dev/null; wait "$HATCHET_API_CHILD_PID" 2>/dev/null; exit 0' SIGTERM SIGINT + + # Start hatchet-api with any passed command line arguments in the background + ./hatchet-api "$@" & + HATCHET_API_CHILD_PID=$! + + wait "$HATCHET_API_CHILD_PID" + echo "$?" > "$HATCHET_API_STATUS_FILE" +) & HATCHET_API_PID=$! -# Start NGINX in the foreground -nginx -g "daemon off;" +( + trap 'nginx -s quit; exit 0' SIGTERM SIGINT + nginx -g "daemon off;" + echo "$?" > "$NGINX_STATUS_FILE" +) & +NGINX_PID=$! + +while true; do + if [ -f "$HATCHET_API_STATUS_FILE" ]; then + EXIT_STATUS=$(cat "$HATCHET_API_STATUS_FILE") + echo "hatchet-api exited with status $EXIT_STATUS; shutting down NGINX..." + nginx -s quit || kill -SIGTERM "$NGINX_PID" 2>/dev/null + wait "$NGINX_PID" 2>/dev/null + rm -f "$HATCHET_API_STATUS_FILE" "$NGINX_STATUS_FILE" + exit "$EXIT_STATUS" + fi + + if [ -f "$NGINX_STATUS_FILE" ]; then + EXIT_STATUS=$(cat "$NGINX_STATUS_FILE") + echo "NGINX exited with status $EXIT_STATUS; shutting down hatchet-api..." + kill -SIGTERM "$HATCHET_API_PID" 2>/dev/null + wait "$HATCHET_API_PID" 2>/dev/null + rm -f "$HATCHET_API_STATUS_FILE" "$NGINX_STATUS_FILE" + exit "$EXIT_STATUS" + fi + + sleep 1 +done