Commit 46c9b31d authored by Guido Trotter's avatar Guido Trotter
Browse files

ConfdInotifyEventHandler: add enable/disable



Make possible to enable and disable the inotify event handler.  The
inotify handler will remain enabled, unless explicitely told to disable
itself.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent d4c1bd12
......@@ -113,15 +113,28 @@ class ConfdInotifyEventHandler(pyinotify.ProcessEvent):
self.mask = pyinotify.EventsCodes.IN_IGNORED | \
pyinotify.EventsCodes.IN_MODIFY
self.file = file
self.add_config_watch()
self.watch_handle = None
self.enable()
def add_config_watch(self):
"""Add a watcher for the ganeti config file
def enable(self):
"""Watch the given file
"""
result = self.watch_manager.add_watch(self.file, self.mask)
if not result[self.file] > 0:
raise errors.ConfdFatalError("Could not add inotify watcher")
if self.watch_handle is None:
result = self.watch_manager.add_watch(self.file, self.mask)
if not self.file in result or result[self.file] <= 0:
raise errors.ConfdFatalError("Could not add inotify watcher")
else:
self.watch_handle = result[self.file]
def disable(self):
"""Stop watching the given file
"""
if self.watch_handle is not None:
result = self.watch_manager.rm_watch(self.watch_handle)
if result[self.watch_handle]:
self.watch_handle = None
def reload_config(self):
try:
......@@ -143,13 +156,14 @@ class ConfdInotifyEventHandler(pyinotify.ProcessEvent):
# contextual with the replacement). In such a case we need to create
# another watcher for the "new" file.
logging.debug("Received 'ignored' inotify event for %s" % event.path)
self.watch_handle = None
try:
# Since the kernel believes the file we were interested in is gone, it's
# not going to notify us of any other events, until we set up, here, the
# new watch. This is not a race condition, though, since we're anyway
# going to realod the file after setting up the new watch.
self.add_config_watch()
self.enable()
self.reload_config()
except errors.ConfdFatalError, err:
logging.critical("Critical error, shutting down: %s" % err)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment