From cde6e0db7e2d69574b9f7cdd90a1c00e95dbdef8 Mon Sep 17 00:00:00 2001 From: Jona Heitzer Date: Sat, 18 Oct 2025 23:38:34 +0200 Subject: [PATCH] Wait for network connection, so gluetun can come up --- irc-topic-bot.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/irc-topic-bot.py b/irc-topic-bot.py index 6b047ca..62f50b0 100644 --- a/irc-topic-bot.py +++ b/irc-topic-bot.py @@ -42,6 +42,16 @@ def log(level, msg): ts = datetime.now().strftime("%Y-%m-%d %H:%M:%S UTC") print(f"[{ts}] [{level}] {msg}", flush=True) +def wait_for_network(host="8.8.8.8", port=53, timeout=3, retry_interval=1): + log("*", "Waiting for network connection") + while True: + log(".", f"Still waiting for network connection, testing {host}:{port}") + try: + with socket.create_connection((host, port), timeout=timeout): + return + except OSError: + time.sleep(retry_interval) + def sendmail(subject, message): try: msg = MIMEText(message) @@ -130,6 +140,8 @@ def connect_to_channel_and_check_topic(): return def main(): + wait_for_network() + try: res = requests.get("https://api.ipify.org", timeout=10) res.raise_for_status()