From f1dac1fe13ea446378502ad368612b5823cb2f65 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Fri, 6 Jun 2014 08:41:57 -0400 Subject: [PATCH] show less output when updating DNS configuration --- management/dns_update.py | 42 ++++++++++++++++++++++++++++------------ setup/start.sh | 2 +- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/management/dns_update.py b/management/dns_update.py index 67a40970..7ac9fb2f 100755 --- a/management/dns_update.py +++ b/management/dns_update.py @@ -31,19 +31,27 @@ def do_dns_update(env): updated_domains.append(domain) # Write the main nsd.conf file. - write_nsd_conf(zonefiles) + if write_nsd_conf(zonefiles): + # Make sure updated_domains contains *something* if we wrote an updated + # nsd.conf so that we know to restart nsd. + if len(updated_domains) == 0: + updated_domains.append("DNS configuration") + + # Kick nsd if anything changed. + if len(updated_domains) > 0: + os.system("service nsd restart") # Write the OpenDKIM configuration tables. write_opendkim_tables(zonefiles, env) - # Kick nsd. - os.system("service nsd restart") - # Kick opendkim. os.system("service opendkim restart") - if len(updated_domains) == 0: updated_domains = ['(no domains required an update)'] - return "Updated: " + ",".join(updated_domains) + "\n" + if len(updated_domains) == 0: + # if nothing was updated (except maybe DKIM), don't show any output + return "" + else: + return "updated: " + ",".join(updated_domains) + "\n" ######################################################################## @@ -136,8 +144,7 @@ $TTL 86400 ; default time to live ######################################################################## def write_nsd_conf(zonefiles): - with open("/etc/nsd/nsd.conf", "w") as f: - f.write(""" + nsdconf = """ server: hide-version: yes @@ -148,14 +155,25 @@ server: zonesdir: "/etc/nsd/zones" # ZONES -""") +""" - for domain, zonefile in zonefiles: - f.write(""" + for domain, zonefile in zonefiles: + nsdconf += """ zone: name: %s zonefile: %s -""" % (domain, zonefile)) +""" % (domain, zonefile) + + # Check if the nsd.conf is changing. If it isn't changing, + # return False to flag that no change was made. + with open("/etc/nsd/nsd.conf") as f: + if f.read() == nsdconf: + return False + + with open("/etc/nsd/nsd.conf", "w") as f: + f.write(nsdconf) + + return True ######################################################################## diff --git a/setup/start.sh b/setup/start.sh index 41ce6cac..e9ccd552 100755 --- a/setup/start.sh +++ b/setup/start.sh @@ -115,7 +115,7 @@ EOF # Write the DNS configuration files. sleep 5 # wait for the daemon to start -curl -d POSTDATA http://127.0.0.1:10222/dns/update +curl -s -d POSTDATA http://127.0.0.1:10222/dns/update # If there aren't any mail users yet, create one. if [ -z "`tools/mail.py user`" ]; then