From 15486fa7a6b2837552076330f34e9aac730932b4 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Fri, 21 Nov 2008 10:46:12 +0000
Subject: [PATCH] ganeti-masterd: Remove PID file at the end

Removing the PID file should be the last thing done. This patch makes
sure it's also removed when master.server_cleanup() throws an exception.

Also initialize logging only after writing the PID file.

Reviewed-by: iustinp
---
 daemons/ganeti-masterd | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/daemons/ganeti-masterd b/daemons/ganeti-masterd
index 9d8635a5c..c2623b9af 100755
--- a/daemons/ganeti-masterd
+++ b/daemons/ganeti-masterd
@@ -446,27 +446,28 @@ def main():
                     noclose_fds=[master.fileno()])
 
   utils.WritePidFile(constants.MASTERD_PID)
-
-  utils.SetupLogging(constants.LOG_MASTERDAEMON, debug=options.debug,
-                     stderr_logging=not options.fork)
-
-  rpc.Init()
   try:
-    logging.info("ganeti master daemon startup")
+    utils.SetupLogging(constants.LOG_MASTERDAEMON, debug=options.debug,
+                       stderr_logging=not options.fork)
 
-    # activate ip
-    master_node = ssconf.SimpleConfigReader().GetMasterNode()
-    if not rpc.RpcRunner.call_node_start_master(master_node, False):
-      logging.error("Can't activate master IP address")
+    logging.info("Ganeti master daemon startup")
 
-    master.setup_queue()
+    rpc.Init()
     try:
-      master.serve_forever()
+      # activate ip
+      master_node = ssconf.SimpleConfigReader().GetMasterNode()
+      if not rpc.RpcRunner.call_node_start_master(master_node, False):
+        logging.error("Can't activate master IP address")
+
+      master.setup_queue()
+      try:
+        master.serve_forever()
+      finally:
+        master.server_cleanup()
     finally:
-      master.server_cleanup()
-      utils.RemovePidFile(constants.MASTERD_PID)
+      rpc.Shutdown()
   finally:
-    rpc.Shutdown()
+    utils.RemovePidFile(constants.MASTERD_PID)
 
 
 if __name__ == "__main__":
-- 
GitLab