Skip to content

Commit

Permalink
Merge pull request #64 from dappnode/dappnodedev/fix-fetch-attempts
Browse files Browse the repository at this point in the history
Fix error being set into txt file
  • Loading branch information
pablomendezroyo authored Jan 8, 2024
2 parents 490c8cb + c81c47d commit dba6ce6
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions bind/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ fetch_env() {
sleep $wait_time
done

echo "Error: Failed to fetch $env_var_name after $retries attempts."
exit 1
echo " [ERROR] Failed to fetch $env_var_name after $retries attempts."
return 1
}

# Start DNS server in background right away
/app/dnscrypt-proxy &

# Initialize domain and internal_ip variables
domain=""
internal_ip=""

pid=$!

# Fetch required environment variables
Expand All @@ -34,19 +38,36 @@ if [ -n "${_DAPPNODE_GLOBAL_DOMAIN}" ]; then
domain=${_DAPPNODE_GLOBAL_DOMAIN}
echo "Using existing domain: $domain"
else
domain=$(fetch_env "DOMAIN")
fetched_domain=$(fetch_env "DOMAIN")

if [ $? -eq 0 ]; then
domain=$fetched_domain
else
echo "[ERROR] Failed to fetch DOMAIN"
fi
fi

if [ -n "${_DAPPNODE_GLOBAL_INTERNAL_IP}" ]; then
internal_ip=${_DAPPNODE_GLOBAL_INTERNAL_IP}
echo "Using existing domain: $domain"
else
internal_ip=$(fetch_env "INTERNAL_IP")
fetched_internal_ip=$(fetch_env "INTERNAL_IP")

if [ $? -eq 0 ]; then
internal_ip=$fetched_internal_ip
else
echo "[ERROR] Failed to fetch INTERNAL_IP"
fi
fi

echo "$domain $internal_ip" >cloaking-rules.txt
# Only write to cloaking-rules.txt if both domain and internal_ip are available
if [ -n "$domain" ] && [ -n "$internal_ip" ]; then
echo "$domain $internal_ip" >cloaking-rules.txt

kill $pid
wait $pid
kill $pid
wait $pid

/app/dnscrypt-proxy
/app/dnscrypt-proxy
else
echo "[ERROR] Missing domain or internal IP. Cloaking rules not updated. Dyndns domain will not be forwarded to internal IP."
fi

0 comments on commit dba6ce6

Please sign in to comment.