From e1adfbd5c2b9a09f75bf62946caa5ab9c3b5db9d Mon Sep 17 00:00:00 2001 From: artemijspavlovs Date: Mon, 19 Feb 2024 17:36:47 +0200 Subject: [PATCH] feat: add script that is used to wait for the hub to become available --- scripts/fraud_proof_poc/wait-for-hub.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 scripts/fraud_proof_poc/wait-for-hub.sh diff --git a/scripts/fraud_proof_poc/wait-for-hub.sh b/scripts/fraud_proof_poc/wait-for-hub.sh new file mode 100644 index 000000000..d6dd3c9f3 --- /dev/null +++ b/scripts/fraud_proof_poc/wait-for-hub.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Target URL +URL="http://hub:36657/status" + +# Wait for the /status endpoint to be available and the latest_block_height to be present +while true; do + # Use curl to fetch the status endpoint and jq to parse the JSON response + HEIGHT=$(curl -s $URL | jq -r '.result.sync_info.latest_block_height') + + # Check if HEIGHT is a number and greater than 0 (modify this check as needed) + if [[ "$HEIGHT" =~ ^[0-9]+$ ]] && [ "$HEIGHT" -gt 0 ]; then + echo "hub is ready with latest_block_height: $HEIGHT" + break + else + echo "Waiting for hub to be ready..." + fi + + sleep 5 # Wait for 5 seconds before trying again +done + +# Proceed with the rest of your script or command to start the service +exec "$@" \ No newline at end of file