From 9e289e362fd6ab7170f75c0aa9a6b190a9e24506 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Fri, 26 Feb 2010 12:25:21 +0100 Subject: [PATCH] Add watcher hooks These hooks are run on all nodes, after the "base" daemons are started. Signed-off-by: Guido Trotter <ultrotter@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- daemons/ganeti-watcher | 26 ++++++++++++++++++++++++++ lib/constants.py | 1 + 2 files changed, 27 insertions(+) diff --git a/daemons/ganeti-watcher b/daemons/ganeti-watcher index 351f4d83b..3d4357f26 100755 --- a/daemons/ganeti-watcher +++ b/daemons/ganeti-watcher @@ -94,6 +94,31 @@ def StartNodeDaemons(): 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 +513,7 @@ def main(): update_file = False try: StartNodeDaemons() + RunWatcherHooks() notepad = WatcherState() try: diff --git a/lib/constants.py b/lib/constants.py index 4fff9e713..20d63fe77 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) -- GitLab