From f9aaa9fdfa42b097b0c4f37d0be98875cc6482c3 Mon Sep 17 00:00:00 2001 From: Carl Baldwin Date: Thu, 5 Jun 2014 21:39:05 +0000 Subject: [PATCH] Sync service module from oslo-incubator 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 | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/neutron/openstack/common/service.py b/neutron/openstack/common/service.py index 627dda4ff..79ae9bc5d 100644 --- a/neutron/openstack/common/service.py +++ b/neutron/openstack/common/service.py @@ -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() -- 2.45.2