From 0525e443fa68cda451c9f4c838e1f55cec913d2a Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Fri, 29 May 2020 20:06:01 +0200 Subject: dynamic-dns: T2528: bugfix FileNotFoundError in "update dns dynamic" Stopping and starting ddclient should only happen if the DNS dynamic service is actually configured. In addition it should always be checked if the file we try to delete really exists. --- src/op_mode/dynamic_dns.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/op_mode/dynamic_dns.py b/src/op_mode/dynamic_dns.py index e4e5043d5..021acfd73 100755 --- a/src/op_mode/dynamic_dns.py +++ b/src/op_mode/dynamic_dns.py @@ -36,12 +36,6 @@ update-status: {{ entry.status }} """ def show_status(): - # Do nothing if service is not configured - c = Config() - if not c.exists_effective('service dns dynamic'): - print("Dynamic DNS not configured") - sys.exit(0) - data = { 'hosts': [] } @@ -86,22 +80,25 @@ def show_status(): def update_ddns(): call('systemctl stop ddclient.service') - os.remove(cache_file) + if os.path.exists(cache_file): + os.remove(cache_file) call('systemctl start ddclient.service') -def main(): +if __name__ == '__main__': parser = argparse.ArgumentParser() group = parser.add_mutually_exclusive_group() group.add_argument("--status", help="Show DDNS status", action="store_true") group.add_argument("--update", help="Update DDNS on a given interface", action="store_true") args = parser.parse_args() + # Do nothing if service is not configured + c = Config() + if not c.exists_effective('service dns dynamic'): + print("Dynamic DNS not configured") + sys.exit(1) + if args.status: show_status() elif args.update: update_ddns() - - -if __name__ == '__main__': - main() -- cgit v1.2.3