X-Git-Url: https://git.llucax.com/software/pymin.git/blobdiff_plain/52d87d11873f1a37b21100700f4798a375361f3f..5a0b7aa969cfabb1d087088975cf013d4d446180:/pymin/services/dns/__init__.py?ds=inline diff --git a/pymin/services/dns/__init__.py b/pymin/services/dns/__init__.py index d34291e..f57386c 100644 --- a/pymin/services/dns/__init__.py +++ b/pymin/services/dns/__init__.py @@ -3,6 +3,7 @@ # TODO COMMENT from os import path from os import unlink +import logging ; log = logging.getLogger('pymin.services.dns') from pymin.seqtools import Sequence from pymin.dispatcher import handler, HandlerError, Handler @@ -105,17 +106,12 @@ class DnsHandler(Restorable, ConfigWriter, InitdHandler, TransactionalHandler, def __init__(self, pickle_dir='.', config_dir='.'): r"Initialize DnsHandler object, see class documentation for details." + log.debug(u'DnsHandler(%r, %r)', pickle_dir, config_dir) self._persistent_dir = pickle_dir self._config_writer_cfg_dir = config_dir self._update = False self._config_build_templates() - self._restore() - # FIXME self._update = True - #if not self._restore(): - #r = self._restore() - #print r - #if not r: - # self._update = True + InitdHandler.__init__(self) self.host = HostHandler(self) self.zone = ZoneHandler(self) self.mx = MailExchangeHandler(self) @@ -129,10 +125,14 @@ class DnsHandler(Restorable, ConfigWriter, InitdHandler, TransactionalHandler, def _write_config(self): r"_write_config() -> None :: Generate all the configuration files." + log.debug(u'DnsHandler._write_config()') delete_zones = list() for a_zone in self.zones.values(): + log.debug(u'DnsHandler._write_config: processing zone %s', a_zone) if a_zone._update or a_zone._add: - if not a_zone._add: + if not a_zone._add and self._service_running: + log.debug(u'DnsHandler._write_config: zone updated and ' + u'the service is running, freezing zone') call(('rndc', 'freeze', a_zone.name)) vars = dict( zone = a_zone, @@ -143,19 +143,23 @@ class DnsHandler(Restorable, ConfigWriter, InitdHandler, TransactionalHandler, self._write_single_config('zoneX.zone', self._zone_filename(a_zone), vars) a_zone._update = False - if not a_zone._add: + if not a_zone._add and self._service_running: + log.debug(u'DnsHandler._write_config: unfreezing zone') call(('rndc', 'thaw', a_zone.name)) else : self._update = True a_zone._add = False if a_zone._delete: #borro el archivo .zone + log.debug(u'DnsHandler._write_config: zone deleted, removing ' + u'the file %r', self._zone_filename(a_zone)) try: self._update = True unlink(self._zone_filename(a_zone)) except OSError: #la excepcion pude darse en caso que haga un add de una zona y #luego el del, como no hice commit, no se crea el archivo + log.debug(u'DnsHandler._write_config: file not found') pass delete_zones.append(a_zone.name) #borro las zonas @@ -165,11 +169,33 @@ class DnsHandler(Restorable, ConfigWriter, InitdHandler, TransactionalHandler, if self._update: self._write_single_config('named.conf') self._update = False - self.reload() + return False # Do reload + return True # we don't need to reload + + # HACK!!!! + def handle_timer(self): + log.debug(u'DnsHandler.handle_timer()') + import subprocess + p = subprocess.Popen(('pgrep', '-f', '/usr/sbin/named'), + stdout=subprocess.PIPE) + pid = p.communicate()[0] + if p.returncode == 0 and len(pid) > 0: + log.debug(u'DnsHandler.handle_timer: pid present, running') + self._service_running = True + else: + log.debug(u'DnsHandler.handle_timer: pid absent, NOT running') + self._service_running = False + if __name__ == '__main__': + logging.basicConfig( + level = logging.DEBUG, + format = '%(asctime)s %(levelname)-8s %(message)s', + datefmt = '%H:%M:%S', + ) + dns = DnsHandler(); dns.set('isp_dns1','la_garcha.com')