From 32ba31be5b6572ece8b03c1c0148f3c765edf6af Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Thu, 20 Dec 2012 14:22:27 +0100
Subject: [PATCH] Stop all daemons on cluster initialization
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Addresses issue 145. When daemons are still running from a previous
cluster instance, starting the daemons again will fail.
β€œConfigWriter.IsCluster” only looks at the configuration file, which
could already have been deleted.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/bootstrap.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/bootstrap.py b/lib/bootstrap.py
index dc9279257..69ba1ef68 100644
--- a/lib/bootstrap.py
+++ b/lib/bootstrap.py
@@ -448,6 +448,13 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
                                                              curr_helper),
                                  errors.ECODE_INVAL)
 
+  logging.debug("Stopping daemons (if any are running)")
+  result = utils.RunCmd([pathutils.DAEMON_UTIL, "stop-all"])
+  if result.failed:
+    raise errors.OpExecError("Could not stop daemons, command %s"
+                             " had exitcode %s and error '%s'" %
+                             (result.cmd, result.exit_code, result.output))
+
   if constants.ENABLE_FILE_STORAGE:
     file_storage_dir = _InitFileStorage(file_storage_dir)
   else:
-- 
GitLab