debug(tunnels): add connectivity check before starting cloudflared tunnel

This commit is contained in:
Fusion
2026-05-20 16:28:39 +02:00
parent 2bd778117f
commit e985f0122e
+21
View File
@@ -258,8 +258,29 @@ def start_cloudflared_tunnel(
import subprocess
import time
import re
import logging
logger = logging.getLogger(__name__)
# First verify the container is accessible
logger.info("Checking connectivity to %s:%d...", container_name, port)
for attempt in range(10):
check = subprocess.run(
["curl", "-s", "-o", "/dev/null", "-w", "%{http_code}",
f"http://{container_name}:{port}"],
capture_output=True,
text=True,
timeout=5,
)
logger.info("Connectivity check %d: http_code=%s", attempt + 1, check.stdout.strip())
if check.returncode == 0:
break
time.sleep(1)
else:
logger.warning("Container %s:%d not responding to curl checks", container_name, port)
# Run cloudflared in background, capture output
logger.info("Starting cloudflared tunnel to http://%s:%d", container_name, port)
proc = subprocess.Popen(
["cloudflared", "tunnel", "--url", f"http://{container_name}:{port}"],
stdout=subprocess.PIPE,