Wait for network connection, so gluetun can come up
This commit is contained in:
@@ -42,6 +42,16 @@ def log(level, msg):
|
|||||||
ts = datetime.now().strftime("%Y-%m-%d %H:%M:%S UTC")
|
ts = datetime.now().strftime("%Y-%m-%d %H:%M:%S UTC")
|
||||||
print(f"[{ts}] [{level}] {msg}", flush=True)
|
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):
|
def sendmail(subject, message):
|
||||||
try:
|
try:
|
||||||
msg = MIMEText(message)
|
msg = MIMEText(message)
|
||||||
@@ -130,6 +140,8 @@ def connect_to_channel_and_check_topic():
|
|||||||
return
|
return
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
wait_for_network()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = requests.get("https://api.ipify.org", timeout=10)
|
res = requests.get("https://api.ipify.org", timeout=10)
|
||||||
res.raise_for_status()
|
res.raise_for_status()
|
||||||
|
|||||||
Reference in New Issue
Block a user