Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync process loop time with TTL if set to auto #178

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions cloudflare-ddns.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,29 +282,28 @@ def updateIPs(ips):
try:
ttl = int(config["ttl"])
except:
ttl = 300 # default Cloudflare TTL
ttl = 1 # default Cloudflare TTL
print(
"⚙️ No config detected for 'ttl' - defaulting to 300 seconds (5 minutes)")
"⚙️ No config detected for 'ttl' - defaulting to 1 (auto)")
if ttl < 30:
ttl = 1 #
ttl = 1
print("⚙️ TTL is too low - defaulting to 1 (auto)")
if (len(sys.argv) > 1):
if (sys.argv[1] == "--repeat"):
if ipv4_enabled and ipv6_enabled:
print(
"🕰️ Updating IPv4 (A) & IPv6 (AAAA) records every " + str(ttl) + " seconds")
elif ipv4_enabled and not ipv6_enabled:
print("🕰️ Updating IPv4 (A) records every " +
str(ttl) + " seconds")
elif ipv6_enabled and not ipv4_enabled:
print("🕰️ Updating IPv6 (AAAA) records every " +
str(ttl) + " seconds")
delay = 300 if ttl == 1 else ttl
configured_ipvs = []
if ipv4_enabled:
configured_ipvs.append("IPv4 (A)")
if ipv6_enabled:
configured_ipvs.append("IPv6 (AAAA)")
configured_ipvs = ' & '.join(configured_ipvs)
print(f"🕰️ Updating {configured_ipvs} records every {str(delay)} seconds")
next_time = time.time()
killer = GracefulExit()
prev_ips = None
while True:
updateIPs(getIPs())
if killer.kill_now.wait(ttl):
if killer.kill_now.wait(delay):
break
else:
print("❓ Unrecognized parameter '" +
Expand Down