summaryrefslogtreecommitdiff
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
parent9d6f9b7a5de846cf5ba0d6c38440729c54be8e28 (diff)
downloadnova-e849aa7112dcf24357d46f39195cfefce828a91a.tar.gz
Removed logging logic from __init__, added concept of Launcher...no tests for it yet.
-rwxr-xr-xbin/nova-api40
-rw-r--r--nova/__init__.py10
-rw-r--r--nova/service.py70
-rw-r--r--nova/wsgi.py1
4 files changed, 81 insertions, 40 deletions
diff --git a/bin/nova-api b/bin/nova-api
index 2345b3f2c3..563d7c0905 100755
--- a/bin/nova-api
+++ b/bin/nova-api
@@ -24,44 +24,26 @@ Starts both the EC2 and OpenStack APIs in separate processes.
"""
import sys
-import multiprocessing
-import nova.flags
import nova.log
import nova.service
import nova.version
-import nova.utils
-
-
-def launch(service_name):
- """Launch WSGI service with name matching 'paste' config file section."""
- service = nova.service.WSGIService(service_name)
- service.start()
- try:
- service.wait()
- except KeyboardInterrupt:
- service.stop()
def main():
- """Begin process of launching both EC2 and OSAPI services."""
- version = nova.version.version_string_with_vcs()
- logger = nova.log.getLogger("nova.api")
- logger.audit(_("Starting nova-api node (version %s)") % version)
-
- nova.flags.FLAGS(sys.argv)
- nova.utils.default_flagfile()
-
- pool = multiprocessing.Pool(2)
- pool.map_async(launch, ["ec2", "osapi"])
- pool.close()
-
+ """Launch EC2 and OSAPI services."""
+ ec2 = nova.service.WSGIService("ec2")
+ osapi = nova.service.WSGIService("osapi")
+
+ launcher = nova.service.Launcher(sys.argv)
+ launcher.launch_service(ec2)
+ launcher.launch_service(osapi)
+
try:
- pool.join()
+ launcher.wait()
except KeyboardInterrupt:
- logger.audit(_("Exiting..."))
- pool.terminate()
-
+ launcher.stop()
+
if __name__ == '__main__':
sys.exit(main())
diff --git a/nova/__init__.py b/nova/__init__.py
index 886eaee206..884c4a7130 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 bb38cddb61..d896de1fe7 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 8a7d38252f..097fa47346 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: