summaryrefslogtreecommitdiffstats
path: root/openstack
diff options
context:
space:
mode:
authorAngus Salkeld <asalkeld@redhat.com>2012-08-15 08:18:48 +1000
committerAngus Salkeld <asalkeld@redhat.com>2012-08-15 08:26:16 +1000
commitb2408dcedbc4c036c50a0df87a634c8946a08c7c (patch)
treecb050c319fb42270bfae21eb44cbdb94b9c2ab1a /openstack
parentc8f9afd4c0de0883e7b64c4d219a47aa88a0d32a (diff)
downloadoslo-b2408dcedbc4c036c50a0df87a634c8946a08c7c.tar.gz
oslo-b2408dcedbc4c036c50a0df87a634c8946a08c7c.tar.xz
oslo-b2408dcedbc4c036c50a0df87a634c8946a08c7c.zip
Basic service launching infrastructure
Part of blueprint service-infrastructure Change-Id: I4e97db2877be976b0c681da9ff0d331fbfb306b0 Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
Diffstat (limited to 'openstack')
-rw-r--r--openstack/common/service.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/openstack/common/service.py b/openstack/common/service.py
index a0a8e5a..9c712c6 100644
--- a/openstack/common/service.py
+++ b/openstack/common/service.py
@@ -19,6 +19,64 @@
"""Generic Node base class for all workers that run on hosts."""
+import sys
+import eventlet
+import greenlet
+
+
+class Launcher(object):
+ """Launch one or more services and wait for them to complete."""
+
+ def __init__(self):
+ """Initialize the service launcher.
+
+ :returns: None
+
+ """
+ self._services = []
+
+ @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()
+ service.wait()
+
+ def launch_service(self, service):
+ """Load and start the given service.
+
+ :param service: The service you would like to start.
+ :returns: None
+
+ """
+ gt = eventlet.spawn(self.run_service, service)
+ self._services.append(gt)
+
+ def stop(self):
+ """Stop all services which are currently running.
+
+ :returns: None
+
+ """
+ for service in self._services:
+ service.kill()
+
+ def wait(self):
+ """Waits until all services have been stopped, and then returns.
+
+ :returns: None
+
+ """
+ for service in self._services:
+ try:
+ service.wait()
+ except greenlet.GreenletExit:
+ pass
+
class Service(object):
"""Service object for binaries running on hosts.
@@ -28,3 +86,18 @@ class Service(object):
def __init__(self, host, manager, *args, **kwargs):
self.host = host
self.manager = manager
+
+ def start(self):
+ if self.manager:
+ self.manager.init_host()
+
+ def stop(self):
+ pass
+
+ def wait(self):
+ pass
+
+
+def launcher(service):
+ l = Launcher()
+ l.launch_service(service)