From cc0c70ed45213ffd1a600db6c6653257e6b2eb8e Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 9 Nov 2017 17:51:32 +0100 Subject: [PATCH] Adding initializing pidfile object --- pp_lib/deploy_zones_from_pdns.py | 34 ++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/pp_lib/deploy_zones_from_pdns.py b/pp_lib/deploy_zones_from_pdns.py index b06f7e9..008dacf 100644 --- a/pp_lib/deploy_zones_from_pdns.py +++ b/pp_lib/deploy_zones_from_pdns.py @@ -38,7 +38,9 @@ from .pdns_app import PDNSApiNotFoundError, PDNSApiValidationError from .pdns_zone import PdnsApiZone from .pdns_record import compare_rrsets -__version__ = '0.2.1' +from .pidfile import PidFileError, InvalidPidFileError, PidFileInUseError, PidFile + +__version__ = '0.2.2' LOG = logging.getLogger(__name__) @@ -93,6 +95,7 @@ class PpDeployZonesApp(PpPDNSApplication): def __init__(self, appname=None, base_dir=None, version=__version__): self.zones = [] + self.pidfile = None self._show_simulate_opt = True @@ -135,7 +138,7 @@ class PpDeployZonesApp(PpPDNSApplication): base_dir=base_dir, cfg_stems='dns-deploy-zones', environment="public", ) - self.initialized = True + self.post_init() # ------------------------------------------- @property @@ -246,6 +249,20 @@ class PpDeployZonesApp(PpPDNSApplication): else: LOG.warn("No valid masters found in configuration.") + # ------------------------------------------------------------------------- + def post_init(self): + + super(PpDeployZonesApp, self).post_init() + self.initialized = False + + LOG.debug("Post init phase.") + + self.pidfile = PidFile( + filename=self.pidfile_name, appname=self.appname, verbose=self.verbose, + base_dir=self.base_dir, simulate=self.simulate) + + self.initialized = True + # ------------------------------------------------------------------------- def pre_run(self): """ @@ -262,7 +279,20 @@ class PpDeployZonesApp(PpPDNSApplication): "please use 'local' or 'public'") self.exit(1) + # ------------------------------------------------------------------------- + def _run(self): + + my_uid = os.geteuid() + if my_uid: + msg = "You must be root to execute this script." + if self.simulate: + LOG.warn(msg) + time.sleep(1) + else: + LOG.error(msg) + self.exit(1) + LOG.info("Here we go again ...") # ============================================================================= -- 2.39.5