from .pidfile import PidFileError, InvalidPidFileError, PidFileInUseError, PidFile
-__version__ = '0.7.2'
+__version__ = '0.7.3'
LOG = logging.getLogger(__name__)
if not self.check_namedconf():
self.restore_configfiles()
self.exit(99)
+ self.apply_config()
except Exception:
self.restore_configfiles()
raise
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))
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
# =============================================================================