Revision 22d3e184 daemons/ganeti-confd
b/daemons/ganeti-confd | ||
---|---|---|
235 | 235 |
try: |
236 | 236 |
self.inotify_handler.enable() |
237 | 237 |
except errors.InotifyError: |
238 |
raise errors.ConfdFatalError(err)
|
|
238 |
self.polling = True
|
|
239 | 239 |
|
240 | 240 |
try: |
241 | 241 |
reloaded = self.processor.reader.Reload() |
... | ... | |
244 | 244 |
else: |
245 | 245 |
logging.debug("Skipped double config reload") |
246 | 246 |
except errors.ConfigurationError: |
247 |
# transform a ConfigurationError in a fatal error, that will cause confd
|
|
248 |
# to quit.
|
|
249 |
raise errors.ConfdFatalError(err)
|
|
247 |
self.DisableConfd()
|
|
248 |
self.inotify_handler.disable()
|
|
249 |
return
|
|
250 | 250 |
|
251 | 251 |
# Reset the timer. If we're polling it will go to the polling rate, if |
252 | 252 |
# we're not it will delay it again to its base safe timeout. |
253 |
self._DisableTimer() |
|
254 |
self._EnableTimer() |
|
253 |
self._ResetTimer() |
|
255 | 254 |
|
256 | 255 |
def _DisableTimer(self): |
257 | 256 |
if self.timer_handle is not None: |
... | ... | |
268 | 267 |
self.timer_handle = self.mainloop.scheduler.enter( |
269 | 268 |
timeout, 1, self.OnTimer, []) |
270 | 269 |
|
270 |
def _ResetTimer(self): |
|
271 |
self._DisableTimer() |
|
272 |
self._EnableTimer() |
|
273 |
|
|
271 | 274 |
def OnTimer(self): |
272 | 275 |
"""Function called when the timer fires |
273 | 276 |
|
274 | 277 |
""" |
275 | 278 |
self.timer_handle = None |
279 |
reloaded = False |
|
280 |
was_disabled = False |
|
276 | 281 |
try: |
277 |
reloaded = self.processor.reader.Reload() |
|
282 |
if self.processor.reader is None: |
|
283 |
was_disabled = True |
|
284 |
self.EnableConfd() |
|
285 |
reloaded = True |
|
286 |
else: |
|
287 |
reloaded = self.processor.reader.Reload() |
|
278 | 288 |
except errors.ConfigurationError: |
279 |
# transform a ConfigurationError in a fatal error, that will cause confd |
|
280 |
# to quit. |
|
281 |
raise errors.ConfdFatalError(err) |
|
289 |
self.DisableConfd() |
|
290 |
return |
|
282 | 291 |
|
283 | 292 |
if self.polling and reloaded: |
284 | 293 |
logging.info("Reloaded ganeti config") |
... | ... | |
286 | 295 |
# We have reloaded the config files, but received no inotify event. If |
287 | 296 |
# an event is pending though, we just happen to have timed out before |
288 | 297 |
# receiving it, so this is not a problem, and we shouldn't alert |
289 |
if not self.notifier.check_events(): |
|
298 |
if not self.notifier.check_events() and not was_disabled:
|
|
290 | 299 |
logging.warning("Config file reload at timeout (inotify failure)") |
291 | 300 |
elif self.polling: |
292 | 301 |
# We're polling, but we haven't reloaded the config: |
293 | 302 |
# Going back to inotify mode |
294 | 303 |
logging.debug("Moving from polling mode to inotify mode") |
295 | 304 |
self.polling = False |
296 |
self.inotify_handler.enable() |
|
305 |
try: |
|
306 |
self.inotify_handler.enable() |
|
307 |
except errors.InotifyError: |
|
308 |
self.polling = True |
|
297 | 309 |
else: |
298 | 310 |
logging.debug("Performed configuration check") |
299 | 311 |
|
300 | 312 |
self._EnableTimer() |
301 | 313 |
|
314 |
def DisableConfd(self): |
|
315 |
"""Puts confd in non-serving mode |
|
316 |
|
|
317 |
""" |
|
318 |
logging.warning("Confd is being disabled") |
|
319 |
self.processor.Disable() |
|
320 |
self.polling = False |
|
321 |
self._ResetTimer() |
|
322 |
|
|
323 |
def EnableConfd(self): |
|
324 |
self.processor.Enable() |
|
325 |
logging.warning("Confd is being enabled") |
|
326 |
self.polling = True |
|
327 |
self._ResetTimer() |
|
328 |
|
|
302 | 329 |
|
303 | 330 |
def CheckConfd(options, args): |
304 | 331 |
"""Initial checks whether to run exit with a failure. |
... | ... | |
310 | 337 |
print >> sys.stderr, "Need HMAC key %s to run" % constants.HMAC_CLUSTER_KEY |
311 | 338 |
sys.exit(constants.EXIT_FAILURE) |
312 | 339 |
|
313 |
ssconf.CheckMasterCandidate(options.debug) |
|
314 |
|
|
315 | 340 |
|
316 | 341 |
def ExecConfd(options, args): |
317 | 342 |
"""Main confd function, executed with PID file held |
Also available in: Unified diff