Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 46 additions & 7 deletions build/package/dashboard-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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