Stop engine service correctly

If SIGINT received right after start of heat engine, in the middle
of start() method, heat engine can not stop correctly. Clean up only
those resources that actually exist.

Change-Id: I496f6284e15b4f71b166cc0713cfd41423cce400
Closes-Bug: #1562042
This commit is contained in:
Oleksii Chuprykov 2016-03-25 18:36:34 +02:00
parent 159e6e74db
commit 151e8b8e62
1 changed files with 17 additions and 14 deletions

View File

@ -407,6 +407,8 @@ class EngineService(service.Service):
def _stop_rpc_server(self):
# Stop rpc connection at first for preventing new requests
if self._rpc_server is None:
return
LOG.debug("Attempting to stop engine service...")
try:
self._rpc_server.stop()
@ -423,20 +425,21 @@ class EngineService(service.Service):
self.worker_service.stop()
# Wait for all active threads to be finished
for stack_id in list(self.thread_group_mgr.groups.keys()):
# Ignore dummy service task
if stack_id == cfg.CONF.periodic_interval:
continue
LOG.info(_LI("Waiting stack %s processing to be finished"),
stack_id)
# Stop threads gracefully
self.thread_group_mgr.stop(stack_id, True)
LOG.info(_LI("Stack %s processing was finished"), stack_id)
self.manage_thread_grp.stop()
ctxt = context.get_admin_context()
service_objects.Service.delete(ctxt, self.service_id)
LOG.info(_LI('Service %s is deleted'), self.service_id)
if self.thread_group_mgr:
for stack_id in list(self.thread_group_mgr.groups.keys()):
# Ignore dummy service task
if stack_id == cfg.CONF.periodic_interval:
continue
LOG.info(_LI("Waiting stack %s processing to be finished"),
stack_id)
# Stop threads gracefully
self.thread_group_mgr.stop(stack_id, True)
LOG.info(_LI("Stack %s processing was finished"), stack_id)
if self.manage_thread_grp:
self.manage_thread_grp.stop()
ctxt = context.get_admin_context()
service_objects.Service.delete(ctxt, self.service_id)
LOG.info(_LI('Service %s is deleted'), self.service_id)
# Terminate the engine process
LOG.info(_LI("All threads were gone, terminating engine"))