summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorBrian Lamar <brian.lamar@rackspace.com>2011-06-20 19:32:18 -0400
committerBrian Lamar <brian.lamar@rackspace.com>2011-06-20 19:32:18 -0400
commite849aa7112dcf24357d46f39195cfefce828a91a (patch)
tree24f748fa92c69142f17d47936c93312019fe6b16 /nova
parent9d6f9b7a5de846cf5ba0d6c38440729c54be8e28 (diff)
Removed logging logic from __init__, added concept of Launcher...no tests for it yet.
Diffstat (limited to 'nova')
-rw-r--r--nova/__init__.py10
-rw-r--r--nova/service.py70
-rw-r--r--nova/wsgi.py1
3 files changed, 70 insertions, 11 deletions
diff --git a/nova/__init__.py b/nova/__init__.py
index 886eaee20..884c4a713 100644
--- a/nova/__init__.py
+++ b/nova/__init__.py
@@ -33,13 +33,5 @@
import gettext
-import log as logging
-
-def initialize():
- gettext.install("nova", unicode=1)
- logging.setup()
- logging.debug(_("Initialized logging."))
-
-
-initialize()
+gettext.install("nova", unicode=1)
diff --git a/nova/service.py b/nova/service.py
index bb38cddb6..d896de1fe 100644
--- a/nova/service.py
+++ b/nova/service.py
@@ -19,10 +19,12 @@
"""Generic Node baseclass for all workers that run on hosts."""
-import greenlet
import inspect
+import multiprocessing
import os
+import greenlet
+
from eventlet import greenthread
from nova import context
@@ -53,6 +55,72 @@ flags.DEFINE_string('api_paste_config', "api-paste.ini",
'File name for the paste.deploy config for nova-api')
+class Launcher(object):
+ """Launch one or more services and wait for them to complete."""
+
+ def __init__(self, _flags=None):
+ """Initialize the service launcher.
+
+ :param _flags: Flags to use for the services we're going to load.
+ :returns: None
+
+ """
+ self._services = []
+ self._version = version.version_string_with_vcs()
+ logging.setup()
+ logging.audit(_("Nova Version (%(_version)s)") % self.__dict__)
+ FLAGS(_flags)
+ utils.default_flagfile()
+
+
+ @staticmethod
+ def run_service(service):
+ """Start and wait for a service to finish.
+
+ :param service: Service to run and wait for.
+ :returns: None
+
+ """
+ service.start()
+ try:
+ service.wait()
+ except KeyboardInterrupt:
+ service.stop()
+
+ def launch_service(self, service):
+ """Load and start the given service.
+
+ :param service: The service you would like to start.
+ :returns: None
+
+ """
+ process = multiprocessing.Process(target=self.run_service,
+ args=(service,))
+ process.start()
+ self._services.append(process)
+
+ def stop(self):
+ """Stop all services which are currently running.
+
+ :returns: None
+
+ """
+ for service in self._services:
+ if service.is_alive():
+ service.terminate()
+
+ def wait(self):
+ """Waits until all services have been stopped, and then returns.
+
+ :returns: None
+
+ """
+ for service in self._services:
+ service.join()
+ logging.info("Process exited with %d" % service.exitcode)
+
+
+
class Service(object):
"""Base class for workers that run on hosts."""
diff --git a/nova/wsgi.py b/nova/wsgi.py
index 8a7d38252..097fa4734 100644
--- a/nova/wsgi.py
+++ b/nova/wsgi.py
@@ -109,7 +109,6 @@ class Server(object):
:returns: None
"""
- LOG.info(_("Waiting for WSGI server to stop."))
try:
self._server.wait()
except greenlet.GreenletExit: