bind: fix reload of dynamic zones

This commit is contained in:
nikolark committed 2016-08-06 17:17:17 +02:00
1 parent 8fe8a1b311
commit b79fdafaa1
1 file changed
+31 -27
+31 -27
View File
@@ -32,8 +32,11 @@ class Command(BaseCommand):
help='Write zone files even if serial is unchanged.'), help='Write zone files even if serial is unchanged.'),
) )
bind_bin = "/etc/init.d/bind9" rndc_bin = "/usr/sbin/rndc"
reload_command = "%s reload" % bind_bin reload_command = "%s reload" % rndc_bin
freeze_command = "%s freeze" % rndc_bin
thaw_command = "%s thaw" % rndc_bin
commands_in_order = [freeze_command, reload_command, thaw_command]
checkzone_bin = "/usr/sbin/named-checkzone" checkzone_bin = "/usr/sbin/named-checkzone"
checkzone_dir = "/tmp/mdb-checkzone" checkzone_dir = "/tmp/mdb-checkzone"
debug = False debug = False
@@ -45,7 +48,7 @@ class Command(BaseCommand):
force = options['force'] force = options['force']
# do the binaries exist? # do the binaries exist?
for f in (self.checkzone_bin, self.bind_bin): for f in (self.checkzone_bin, self.rndc_bin):
if not os.path.isfile(f) and not debug: if not os.path.isfile(f) and not debug:
print("ERROR: no such file %s, exiting..." % f) print("ERROR: no such file %s, exiting..." % f)
if not debug: if not debug:
@@ -73,30 +76,31 @@ class Command(BaseCommand):
# reload and send email with changes # reload and send email with changes
if self.changes and not debug: if self.changes and not debug:
sys.stdout.write("reloading bind... ") sys.stdout.write("reloading zones... ")
status, output = getstatusoutput(self.reload_command) for command in self.commands_in_order:
if status != 0: status, output = getstatusoutput(command)
sys.stdout.write("fail\n") if status != 0:
message = ( sys.stdout.write("fail\n")
"Failed to reload bind, please inspect...\n\n" + message = (
"%s@%s# %s" % ( "Failed to reload zones, please inspect...\n\n" +
os.getlogin(), os.uname()[1], self.reload_command) + "%s@%s$ %s" % (
"\n%s\n\n\n%s\n\n\n%s" % (output, errors, diffs)) os.getlogin(), os.uname()[1], command) +
mail_admins( "\n%s\n\n\n%s\n\n\n%s" % (output, errors, diffs))
subject="FAIL: bind (%s changed: %s)" % (len(self.changes), zones), mail_admins(
message=message, subject="FAIL: bind (%s changed: %s)" % (len(self.changes), zones),
html_message='<pre>%s</pre>' % message) message=message,
sys.exit(1) html_message='<pre>%s</pre>' % message)
else: sys.exit(1)
sys.stdout.write("ok\n")
message = ( sys.stdout.write("ok\n")
"Successfully updated bind zone files\n\n" + message = (
"%s\n\n%s" % (errors, diffs)) "Successfully updated bind zone files\n\n" +
mail_admins( "%s\n\n%s" % (errors, diffs))
subject="Success: bind (%s changed: %s)" % (len(self.changes), zones), mail_admins(
message=message, subject="Success: bind (%s changed: %s)" % (len(self.changes), zones),
html_message='<pre>%s</pre>' % message) message=message,
sys.exit(0) html_message='<pre>%s</pre>' % message)
sys.exit(0)
def update_zone(self, zone): def update_zone(self, zone):
zonetype = getattr(zone._meta, 'verbose_name', None) \ zonetype = getattr(zone._meta, 'verbose_name', None) \