Convert ganeti daemons to the three-stage startup
authorIustin Pop <iustin@google.com>
Wed, 6 Oct 2010 07:57:41 +0000 (09:57 +0200)
committerIustin Pop <iustin@google.com>
Thu, 7 Oct 2010 08:31:48 +0000 (10:31 +0200)
This makes almost all of the daemons show error messages, and not return
until they finished listening on the appropriate sockets.

Masterd is the only one "special", as it doesn't do enough
initialization in the server creation, only later.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

daemons/ganeti-confd
daemons/ganeti-masterd
daemons/ganeti-noded
daemons/ganeti-rapi

index 45d3cdb..0f5de4f 100755 (executable)
@@ -258,12 +258,13 @@ def CheckConfd(_, args):
   # conflict with that. If so, we might warn or EXIT_FAILURE.
 
 
-def ExecConfd(options, _dummy1, _dummy2):
-  """Main confd function, executed with PID file held
+def PrepConfd(options, _):
+  """Prep confd function, executed with PID file held
 
   """
   # TODO: clarify how the server and reloader variables work (they are
   # not used)
+
   # pylint: disable-msg=W0612
   mainloop = daemon.Mainloop()
 
@@ -281,6 +282,14 @@ def ExecConfd(options, _dummy1, _dummy2):
   # Configuration reloader
   reloader = ConfdConfigurationReloader(processor, mainloop)
 
+  return mainloop
+
+
+def ExecConfd(options, args, prep_data): # pylint: disable-msg=W0613
+  """Main confd function, executed with PID file held
+
+  """
+  mainloop = prep_data
   mainloop.Run()
 
 
@@ -293,7 +302,7 @@ def main():
                         version="%%prog (ganeti) %s" %
                         constants.RELEASE_VERSION)
 
-  daemon.GenericMain(constants.CONFD, parser, CheckConfd, None, ExecConfd)
+  daemon.GenericMain(constants.CONFD, parser, CheckConfd, PrepConfd, ExecConfd)
 
 
 if __name__ == "__main__":
index 2e571b9..6c9471e 100755 (executable)
@@ -530,8 +530,8 @@ def CheckMasterd(options, args):
   utils.RunInSeparateProcess(ActivateMasterIP)
 
 
-def ExecMasterd(options, args, _): # pylint: disable-msg=W0613
-  """Main master daemon function, executed with the PID file held.
+def PrepMasterd(options, _):
+  """Prep master daemon function, executed with the PID file held.
 
   """
   # This is safe to do as the pid file guarantees against
@@ -541,6 +541,14 @@ def ExecMasterd(options, args, _): # pylint: disable-msg=W0613
   mainloop = daemon.Mainloop()
   master = MasterServer(mainloop, constants.MASTER_SOCKET,
                         options.uid, options.gid)
+  return (mainloop, master)
+
+
+def ExecMasterd(options, args, prep_data): # pylint: disable-msg=W0613
+  """Main master daemon function, executed with the PID file held.
+
+  """
+  (mainloop, master) = prep_data
   try:
     rpc.Init()
     try:
@@ -568,7 +576,7 @@ def main():
   parser.add_option("--yes-do-it", dest="yes_do_it",
                     help="Override interactive check for --no-voting",
                     default=False, action="store_true")
-  daemon.GenericMain(constants.MASTERD, parser, CheckMasterd, None,
+  daemon.GenericMain(constants.MASTERD, parser, CheckMasterd, PrepMasterd,
                      ExecMasterd, multithreaded=True)
 
 
index 819bad7..83177fe 100755 (executable)
@@ -914,8 +914,8 @@ def CheckNoded(_, args):
     sys.exit(constants.EXIT_FAILURE)
 
 
-def ExecNoded(options, _dummy1, _dummy2):
-  """Main node daemon function, executed with the PID file held.
+def PrepNoded(options, _):
+  """Preparation node daemon function, executed with the PID file held.
 
   """
   if options.mlock:
@@ -947,6 +947,13 @@ def ExecNoded(options, _dummy1, _dummy2):
                           ssl_params=ssl_params, ssl_verify_peer=True,
                           request_executor_class=request_executor_class)
   server.Start()
+  return (mainloop, server)
+
+def ExecNoded(options, args, prep_data): # pylint: disable-msg=W0613
+  """Main node daemon function, executed with the PID file held.
+
+  """
+  (mainloop, server) = prep_data
   try:
     mainloop.Run()
   finally:
@@ -965,7 +972,7 @@ def main():
                     help="Do not mlock the node memory in ram",
                     default=True, action="store_false")
 
-  daemon.GenericMain(constants.NODED, parser, CheckNoded, None, ExecNoded,
+  daemon.GenericMain(constants.NODED, parser, CheckNoded, PrepNoded, ExecNoded,
                      default_ssl_cert=constants.NODED_CERT_FILE,
                      default_ssl_key=constants.NODED_CERT_FILE,
                      console_logging=True)
index f861a0b..5251652 100755 (executable)
@@ -280,8 +280,8 @@ def CheckRapi(options, args):
     options.ssl_params = None
 
 
-def ExecRapi(options, _dummy1, _dummy2):
-  """Main remote API function, executed with the PID file held.
+def PrepRapi(options, _):
+  """Prep remote API function, executed with the PID file held.
 
   """
 
@@ -301,6 +301,13 @@ def ExecRapi(options, _dummy1, _dummy2):
   # pylint: disable-msg=E1101
   # it seems pylint doesn't see the second parent class there
   server.Start()
+  return (mainloop, server)
+
+def ExecRapi(options, args, prep_data): # pylint: disable-msg=W0613
+  """Main remote API function, executed with the PID file held.
+
+  """
+  (mainloop, server) = prep_data
   try:
     mainloop.Run()
   finally:
@@ -315,7 +322,7 @@ def main():
                     usage="%prog [-f] [-d] [-p port] [-b ADDRESS]",
                     version="%%prog (ganeti) %s" % constants.RELEASE_VERSION)
 
-  daemon.GenericMain(constants.RAPI, parser, CheckRapi, None, ExecRapi,
+  daemon.GenericMain(constants.RAPI, parser, CheckRapi, PrepRapi, ExecRapi,
                      default_ssl_cert=constants.RAPI_CERT_FILE,
                      default_ssl_key=constants.RAPI_CERT_FILE)