From 6089780b73014fa85e2faaa7321c9ede054bc2eb Mon Sep 17 00:00:00 2001 From: Josh Hunt Date: Thu, 17 Jul 2025 18:18:29 +0100 Subject: [PATCH] E2E: Use while/curl loop for waiting for the server to come up (#108259) * E2E: Use while/curl loop for waiting for the server to come up * add 60s timeout --- scripts/grafana-server/wait-for-grafana | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/grafana-server/wait-for-grafana b/scripts/grafana-server/wait-for-grafana index 54ff393b7a8..7ed31822f38 100755 --- a/scripts/grafana-server/wait-for-grafana +++ b/scripts/grafana-server/wait-for-grafana @@ -6,6 +6,20 @@ set -eo pipefail HOST=${HOST:-$DEFAULT_HOST} PORT=${PORT:-$DEFAULT_PORT} -echo -e "Waiting for grafana-server to finish starting, host=$HOST, port=$PORT" +printf "Waiting for grafana-server to finish starting, host=%s, port=%s" "$HOST" "$PORT" -timeout 60 bash -c 'until nc -z $0 $1; do sleep 1; done' $HOST $PORT +timeout=60 +elapsed=0 + +while ! curl -s -f http://$HOST:$PORT/health > /dev/null 2>&1; do + if [ $elapsed -ge $timeout ]; then + printf "\nTimeout after %d seconds waiting for grafana-server to start\n" "$timeout" + exit 1 + fi + + printf "." + sleep 1 + elapsed=$((elapsed + 1)) +done + +printf "\n"