]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Applying changed configuration to named
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 10 Aug 2017 12:10:36 +0000 (14:10 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 10 Aug 2017 12:10:36 +0000 (14:10 +0200)
pp_lib/config_named_app.py

index 4d9f947223fd7762fe35bcfcf50e74a1be860fde..eee79b7382127d3c913fe51e4cbdc993e417737d 100644 (file)
@@ -45,7 +45,7 @@ from .cfg_app import PpCfgAppError, PpConfigApplication
 
 from .pidfile import PidFileError, InvalidPidFileError, PidFileInUseError, PidFile
 
-__version__ = '0.7.2'
+__version__ = '0.7.3'
 LOG = logging.getLogger(__name__)
 
 
@@ -874,6 +874,7 @@ class PpConfigNamedApp(PpConfigApplication):
                 if not self.check_namedconf():
                     self.restore_configfiles()
                     self.exit(99)
+                self.apply_config()
             except Exception:
                 self.restore_configfiles()
                 raise
@@ -1725,7 +1726,7 @@ class PpConfigNamedApp(PpConfigApplication):
         LOG.debug("Return value: {!r}".format(ret_val))
         if std_out and std_out.strip():
             s = to_str(std_out.strip())
-            LOG.debug("Output on STDOUT: {}".format(s))
+            LOG.warn("Output on STDOUT: {}".format(s))
         if std_err and std_err.strip():
             s = to_str(std_err.strip())
             LOG.warn("Output on STDERR: {}".format(s))
@@ -1735,6 +1736,163 @@ class PpConfigNamedApp(PpConfigApplication):
 
         return True
 
+    # -------------------------------------------------------------------------
+    def apply_config(self):
+
+        if not self.reload_necessary and not self.restart_necessary:
+            LOG.info("Reload or restart of named is not necessary.")
+            return
+
+        running = self.named_running()
+        if not running:
+            LOG.warn("Named is not running, please start it manually.")
+            return
+
+        if self.restart_necessary:
+            self.restart_named()
+        else:
+            self.reload_named()
+
+    # -------------------------------------------------------------------------
+    def named_running(self):
+
+        LOG.debug("Checking, whether named is running ...")
+
+        cmd = shlex.split(self.cmd_status)
+        LOG.debug("Executing: {}".format(' '.join(cmd)))
+
+        std_out = None
+        std_err = None
+        ret_val = None
+
+        with Popen(cmd, stdout=PIPE, stderr=PIPE) as proc:
+            try:
+                std_out, std_err = proc.communicate(timeout=10)
+            except TimeoutExpired:
+                proc.kill()
+                std_out, std_err = proc.communicate()
+            ret_val = proc.wait()
+
+        LOG.debug("Return value: {!r}".format(ret_val))
+        if std_out and std_out.strip():
+            s = to_str(std_out.strip())
+            LOG.debug("Output on STDOUT:\n{}".format(s))
+        if std_err and std_err.strip():
+            s = to_str(std_err.strip())
+            LOG.warn("Output on STDERR: {}".format(s))
+
+        if ret_val:
+            return False
+
+        return True
+
+    # -------------------------------------------------------------------------
+    def start_named(self):
+
+        LOG.info("Starting named ...")
+
+        cmd = shlex.split(self.cmd_start)
+        LOG.debug("Executing: {}".format(' '.join(cmd)))
+
+        if self.simulate:
+            return
+
+        std_out = None
+        std_err = None
+        ret_val = None
+
+        with Popen(cmd, stdout=PIPE, stderr=PIPE) as proc:
+            try:
+                std_out, std_err = proc.communicate(timeout=30)
+            except TimeoutExpired:
+                proc.kill()
+                std_out, std_err = proc.communicate()
+            ret_val = proc.wait()
+
+        LOG.debug("Return value: {!r}".format(ret_val))
+        if std_out and std_out.strip():
+            s = to_str(std_out.strip())
+            LOG.debug("Output on STDOUT:\n{}".format(s))
+        if std_err and std_err.strip():
+            s = to_str(std_err.strip())
+            LOG.error("Output on STDERR: {}".format(s))
+
+        if ret_val:
+            return False
+
+        return True
+
+    # -------------------------------------------------------------------------
+    def restart_named(self):
+
+        LOG.info("Restarting named ...")
+
+        cmd = shlex.split(self.cmd_restart)
+        LOG.debug("Executing: {}".format(' '.join(cmd)))
+
+        if self.simulate:
+            return
+
+        std_out = None
+        std_err = None
+        ret_val = None
+
+        with Popen(cmd, stdout=PIPE, stderr=PIPE) as proc:
+            try:
+                std_out, std_err = proc.communicate(timeout=30)
+            except TimeoutExpired:
+                proc.kill()
+                std_out, std_err = proc.communicate()
+            ret_val = proc.wait()
+
+        LOG.debug("Return value: {!r}".format(ret_val))
+        if std_out and std_out.strip():
+            s = to_str(std_out.strip())
+            LOG.debug("Output on STDOUT:\n{}".format(s))
+        if std_err and std_err.strip():
+            s = to_str(std_err.strip())
+            LOG.error("Output on STDERR: {}".format(s))
+
+        if ret_val:
+            return False
+
+        return True
+
+    # -------------------------------------------------------------------------
+    def reload_named(self):
+
+        LOG.info("Reloading named ...")
+
+        cmd = shlex.split(self.cmd_reload)
+        LOG.debug("Executing: {}".format(' '.join(cmd)))
+
+        if self.simulate:
+            return
+
+        std_out = None
+        std_err = None
+        ret_val = None
+
+        with Popen(cmd, stdout=PIPE, stderr=PIPE) as proc:
+            try:
+                std_out, std_err = proc.communicate(timeout=30)
+            except TimeoutExpired:
+                proc.kill()
+                std_out, std_err = proc.communicate()
+            ret_val = proc.wait()
+
+        LOG.debug("Return value: {!r}".format(ret_val))
+        if std_out and std_out.strip():
+            s = to_str(std_out.strip())
+            LOG.debug("Output on STDOUT:\n{}".format(s))
+        if std_err and std_err.strip():
+            s = to_str(std_err.strip())
+            LOG.error("Output on STDERR: {}".format(s))
+
+        if ret_val:
+            return False
+
+        return True
 
 # =============================================================================