🦢 Graceful warnings when config.json path is not configured correctly

This commit is contained in:
Timothy Miller 2021-03-12 15:58:36 -05:00
parent 55b705072a
commit 47ae1238e2

View File

@ -9,7 +9,6 @@ if(version < 3.5):
raise Exception("This script requires Python 3.5+") raise Exception("This script requires Python 3.5+")
class GracefulExit: class GracefulExit:
def __init__(self): def __init__(self):
self.kill_now = threading.Event() self.kill_now = threading.Event()
signal.signal(signal.SIGINT, self.exit_gracefully) signal.signal(signal.SIGINT, self.exit_gracefully)
@ -19,8 +18,13 @@ class GracefulExit:
print("🛑 Stopping main thread...") print("🛑 Stopping main thread...")
self.kill_now.set() self.kill_now.set()
config = None
try:
with open(PATH + "config.json") as config_file: with open(PATH + "config.json") as config_file:
config = json.loads(config_file.read()) config = json.loads(config_file.read())
except:
print("😡 Error reading config.json")
time.sleep(60) # wait 60 seconds to prevent excessive logging on docker auto restart
def deleteEntries(type): def deleteEntries(type):
# Helper function for deleting A or AAAA records # Helper function for deleting A or AAAA records
@ -36,7 +40,7 @@ def deleteEntries(type):
"zones/" + c['zone_id'] + "/dns_records/" + identifier, "DELETE", c) "zones/" + c['zone_id'] + "/dns_records/" + identifier, "DELETE", c)
print("🗑️ Deleted stale record " + identifier) print("🗑️ Deleted stale record " + identifier)
except Exception: except Exception:
print("😡 Error deleting " + type + " record(s)") print("🤷 No " + type + " record(s) found")
def getIPs(): def getIPs():
global shown_ipv4_warning global shown_ipv4_warning
@ -151,7 +155,7 @@ def updateIPs(ips):
for ip in ips.values(): for ip in ips.values():
commitRecord(ip) commitRecord(ip)
if __name__ == '__main__': if __name__ == '__main__' and config is not None:
if(len(sys.argv) > 1): if(len(sys.argv) > 1):
if(sys.argv[1] == "--repeat"): if(sys.argv[1] == "--repeat"):
delay = 60 delay = 60
@ -162,10 +166,8 @@ if __name__ == '__main__':
while True: while True:
if killer.kill_now.wait(delay): if killer.kill_now.wait(delay):
break break
ips = getIPs() updateIPs(getIPs())
if ips != prev_ips:
updateIPs(ips)
else: else:
print("😡 Unrecognized parameter '" + sys.argv[1] + "'. Stopping now.") print("❓ Unrecognized parameter '" + sys.argv[1] + "'. Stopping now.")
else: else:
updateIPs(getIPs()) updateIPs(getIPs())