From 2826b3618362166bcd49d008beffd0fadbd59219 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Fri, 26 Feb 2010 13:41:40 +0100 Subject: [PATCH] Move watcher's EnsureDaemon function to utils This is going to be used from the nbma repository, to ensure that the nld daemon is running. Signed-off-by: Guido Trotter <ultrotter@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- daemons/ganeti-watcher | 21 ++++----------------- lib/utils.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/daemons/ganeti-watcher b/daemons/ganeti-watcher index 3d4357f26..7fc2dc537 100755 --- a/daemons/ganeti-watcher +++ b/daemons/ganeti-watcher @@ -71,27 +71,14 @@ def ShouldPause(): return bool(utils.ReadWatcherPauseFile(constants.WATCHER_PAUSEFILE)) -def EnsureDaemon(name): - """Check for and start daemon if not alive. - - """ - result = utils.RunCmd([constants.DAEMON_UTIL, "check-and-start", name]) - if result.failed: - logging.error("Can't start daemon '%s', failure %s, output: %s", - name, result.fail_reason, result.output) - return False - - return True - - def StartNodeDaemons(): """Start all the daemons that should be running on all nodes. """ # on master or not, try to start the node dameon - EnsureDaemon(constants.NODED) + utils.EnsureDaemon(constants.NODED) # start confd as well. On non candidates it will be in disabled mode. - EnsureDaemon(constants.CONFD) + utils.EnsureDaemon(constants.CONFD) def RunWatcherHooks(): @@ -527,14 +514,14 @@ def main(): except luxi.NoMasterError, err: logging.warning("Master seems to be down (%s), trying to restart", str(err)) - if not EnsureDaemon(constants.MASTERD): + if not utils.EnsureDaemon(constants.MASTERD): logging.critical("Can't start the master, exiting") sys.exit(constants.EXIT_FAILURE) # else retry the connection client = cli.GetClient() # we are on master now - EnsureDaemon(constants.RAPI) + utils.EnsureDaemon(constants.RAPI) try: watcher = Watcher(options, notepad) diff --git a/lib/utils.py b/lib/utils.py index ec08b1eb6..6877dc704 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -1610,6 +1610,19 @@ def DaemonPidFileName(name): return os.path.join(constants.RUN_GANETI_DIR, "%s.pid" % name) +def EnsureDaemon(name): + """Check for and start daemon if not alive. + + """ + result = RunCmd([constants.DAEMON_UTIL, "check-and-start", name]) + if result.failed: + logging.error("Can't start daemon '%s', failure %s, output: %s", + name, result.fail_reason, result.output) + return False + + return True + + def WritePidFile(name): """Write the current process pidfile. -- GitLab