Revision 46c9b31d
b/daemons/ganeti-confd | ||
---|---|---|
113 | 113 |
self.mask = pyinotify.EventsCodes.IN_IGNORED | \ |
114 | 114 |
pyinotify.EventsCodes.IN_MODIFY |
115 | 115 |
self.file = file |
116 |
self.add_config_watch() |
|
116 |
self.watch_handle = None |
|
117 |
self.enable() |
|
117 | 118 |
|
118 |
def add_config_watch(self):
|
|
119 |
"""Add a watcher for the ganeti config file
|
|
119 |
def enable(self):
|
|
120 |
"""Watch the given file
|
|
120 | 121 |
|
121 | 122 |
""" |
122 |
result = self.watch_manager.add_watch(self.file, self.mask) |
|
123 |
if not result[self.file] > 0: |
|
124 |
raise errors.ConfdFatalError("Could not add inotify watcher") |
|
123 |
if self.watch_handle is None: |
|
124 |
result = self.watch_manager.add_watch(self.file, self.mask) |
|
125 |
if not self.file in result or result[self.file] <= 0: |
|
126 |
raise errors.ConfdFatalError("Could not add inotify watcher") |
|
127 |
else: |
|
128 |
self.watch_handle = result[self.file] |
|
129 |
|
|
130 |
def disable(self): |
|
131 |
"""Stop watching the given file |
|
132 |
|
|
133 |
""" |
|
134 |
if self.watch_handle is not None: |
|
135 |
result = self.watch_manager.rm_watch(self.watch_handle) |
|
136 |
if result[self.watch_handle]: |
|
137 |
self.watch_handle = None |
|
125 | 138 |
|
126 | 139 |
def reload_config(self): |
127 | 140 |
try: |
... | ... | |
143 | 156 |
# contextual with the replacement). In such a case we need to create |
144 | 157 |
# another watcher for the "new" file. |
145 | 158 |
logging.debug("Received 'ignored' inotify event for %s" % event.path) |
159 |
self.watch_handle = None |
|
146 | 160 |
|
147 | 161 |
try: |
148 | 162 |
# Since the kernel believes the file we were interested in is gone, it's |
149 | 163 |
# not going to notify us of any other events, until we set up, here, the |
150 | 164 |
# new watch. This is not a race condition, though, since we're anyway |
151 | 165 |
# going to realod the file after setting up the new watch. |
152 |
self.add_config_watch()
|
|
166 |
self.enable()
|
|
153 | 167 |
self.reload_config() |
154 | 168 |
except errors.ConfdFatalError, err: |
155 | 169 |
logging.critical("Critical error, shutting down: %s" % err) |
Also available in: Unified diff