Removed logging logic from __init__, added concept of Launcher...no tests for it yet.
This commit is contained in:
parent
9d6f9b7a5d
commit
e849aa7112
38
bin/nova-api
38
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())
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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."""
|
||||
|
||||
|
|
|
@ -109,7 +109,6 @@ class Server(object):
|
|||
:returns: None
|
||||
|
||||
"""
|
||||
LOG.info(_("Waiting for WSGI server to stop."))
|
||||
try:
|
||||
self._server.wait()
|
||||
except greenlet.GreenletExit:
|
||||
|
|
Loading…
Reference in New Issue