diff --git a/content/docker-entrypoint.sh b/content/docker-entrypoint.sh index 2e4937e..5fdd6f3 100644 --- a/content/docker-entrypoint.sh +++ b/content/docker-entrypoint.sh @@ -1,4 +1,5 @@ UNLOCK_ACCOUNTS="" +UNLOCK_ARGS="" if [ -n "$UNLOCK_START_INDEX" ]; then INDEX=0 END_INDEX=$(($UNLOCK_START_INDEX + $UNLOCK_NUMBER)) @@ -18,8 +19,18 @@ fi echo "Starting geth..." PUBLIC_IP_ARGS="" -if [[ "${NAT_PUBLIC_IP_AUTO}" == "true" ]]; then - PUBLIC_IP_ARGS=--nat=extip:$(curl https://ipinfo.io/ip) +if [[ -n "${NAT_PUBLIC_IP_AUTO}" ]]; then + # Run for 60 seconds if fail + WAIT=60 + SECONDS=0 + SLEEP=5 + while (( SECONDS < WAIT )); do + PUBLIC_IP_ARGS=--nat=extip:$(curl -s -f -m 5 "${NAT_PUBLIC_IP_AUTO}") + # Check if exit code is 0 and returned value is not empty + [[ $? -eq 0 && -n "${PUBLIC_IP_ARGS}" ]] && { echo "Public: Set extip: ${PUBLIC_IP_ARGS}"; break; } || { echo "Can't get Public IP - Retry in $SLEEP seconds / $((WAIT - SECONDS))"; } + # Sleep and check again + sleep $SLEEP + done fi if [ -n "$ENABLE_MINER" ]; then