These hooks are run on all nodes, after the "base" daemons are started.
Signed-off-by: Guido Trotter <[email protected]> --- daemons/ganeti-watcher | 25 +++++++++++++++++++++++++ lib/constants.py | 1 + 2 files changed, 26 insertions(+), 0 deletions(-) diff --git a/daemons/ganeti-watcher b/daemons/ganeti-watcher index 351f4d8..58331c8 100755 --- a/daemons/ganeti-watcher +++ b/daemons/ganeti-watcher @@ -93,6 +93,30 @@ def StartNodeDaemons(): # start confd as well. On non candidates it will be in disabled mode. EnsureDaemon(constants.CONFD) +def RunWatcherHooks(): + """Run the watcher hooks. + + """ + hooks_dir = os.path.join(constants.HOOKS_BASE_DIR, + constants.HOOKS_NAME_WATCHER) + + try: + results = utils.RunParts(hooks_dir) + except Exception, msg: # pylint: disable-msg=W0703 + logging.critical("RunParts %s failed: %s", hooks_dir, msg) + + for (relname, status, runresult) in results: + if status == constants.RUNPARTS_SKIP: + logging.debug("Watcher Hook %s: skipped", relname) + elif status == constants.RUNPARTS_ERR: + logging.warning("Watcher Hook %s: error (%s)", relname, runresult) + elif status == constants.RUNPARTS_RUN: + if runresult.failed: + logging.warning("Watcher Hook %s: failed (exit: %d) (output: %s)", + relname, runresult.exit_code, runresult.output) + else: + logging.debug("Watcher Hook %s: success (output: %s)", relname, + runresult.output) class WatcherState(object): """Interface to a state file recording restart attempts. @@ -488,6 +512,7 @@ def main(): update_file = False try: StartNodeDaemons() + RunWatcherHooks() notepad = WatcherState() try: diff --git a/lib/constants.py b/lib/constants.py index 4fff9e7..20d63fe 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -191,6 +191,7 @@ HOOKS_BASE_DIR = CONF_DIR + "/hooks" HOOKS_PHASE_PRE = "pre" HOOKS_PHASE_POST = "post" HOOKS_NAME_CFGUPDATE = "config-update" +HOOKS_NAME_WATCHER = "watcher" HOOKS_VERSION = 2 # hooks subject type (what object type does the LU deal with) -- 1.6.6.1
