]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Sync service module from oslo-incubator
authorCarl Baldwin <carl.baldwin@hp.com>
Thu, 5 Jun 2014 21:39:05 +0000 (21:39 +0000)
committerCarl Baldwin <carl.baldwin@hp.com>
Thu, 5 Jun 2014 21:43:23 +0000 (21:43 +0000)
This is needed for the stop method now implemented in service.py used here:
https://review.openstack.org/#/c/72564

Current oslo-incubator commit on HEAD
ad3c887fbfc81ac3502a3e49c1ed6c2824029c25

Change-Id: I66901c0c42472be1aadab803958932bcb9be8ee1

neutron/openstack/common/service.py

index 627dda4ffddac822aa59c390bca21fe1556f5d6e..79ae9bc5d0dcae51be3244e2a116dc575bd732a3 100644 (file)
@@ -190,6 +190,7 @@ class ServiceLauncher(Launcher):
         return status, signo
 
     def wait(self, ready_callback=None):
+        systemd.notify_once()
         while True:
             self.handle_signal()
             status, signo = self._wait_for_exit_or_signal(ready_callback)
@@ -267,7 +268,7 @@ class ProcessLauncher(object):
             launcher.wait()
         except SignalExit as exc:
             signame = _signo_to_signame(exc.signo)
-            LOG.info(_LI('Caught %s, exiting'), signame)
+            LOG.info(_LI('Child caught %s, exiting'), signame)
             status = exc.code
             signo = exc.signo
         except SystemExit as exc:
@@ -382,6 +383,7 @@ class ProcessLauncher(object):
     def wait(self):
         """Loop waiting on children to die and respawning as necessary."""
 
+        systemd.notify_once()
         LOG.debug('Full set of CONF:')
         CONF.log_opt_values(LOG, std_logging.DEBUG)
 
@@ -389,9 +391,12 @@ class ProcessLauncher(object):
             while True:
                 self.handle_signal()
                 self._respawn_children()
-                if self.sigcaught:
-                    signame = _signo_to_signame(self.sigcaught)
-                    LOG.info(_LI('Caught %s, stopping children'), signame)
+                # No signal means that stop was called.  Don't clean up here.
+                if not self.sigcaught:
+                    return
+
+                signame = _signo_to_signame(self.sigcaught)
+                LOG.info(_LI('Caught %s, stopping children'), signame)
                 if not _is_sighup_and_daemon(self.sigcaught):
                     break
 
@@ -402,6 +407,11 @@ class ProcessLauncher(object):
         except eventlet.greenlet.GreenletExit:
             LOG.info(_LI("Wait called after thread killed.  Cleaning up."))
 
+        self.stop()
+
+    def stop(self):
+        """Terminate child processes and wait on each."""
+        self.running = False
         for pid in self.children:
             try:
                 os.kill(pid, signal.SIGTERM)
@@ -488,7 +498,6 @@ class Services(object):
 
         """
         service.start()
-        systemd.notify_once()
         done.wait()