mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Make sure to not leave hanging children processes if the parent is killed
This commit is contained in:
parent
943476646a
commit
baacda2286
@ -5,6 +5,7 @@ The main entry point for salt-api
|
|||||||
# Import python libs
|
# Import python libs
|
||||||
import logging
|
import logging
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
import signal
|
||||||
|
|
||||||
# Import salt-api libs
|
# Import salt-api libs
|
||||||
import salt.loader
|
import salt.loader
|
||||||
@ -18,6 +19,7 @@ class NetapiClient(object):
|
|||||||
'''
|
'''
|
||||||
def __init__(self, opts):
|
def __init__(self, opts):
|
||||||
self.opts = opts
|
self.opts = opts
|
||||||
|
self.processes = []
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
'''
|
'''
|
||||||
@ -27,4 +29,17 @@ class NetapiClient(object):
|
|||||||
for fun in netapi:
|
for fun in netapi:
|
||||||
if fun.endswith('.start'):
|
if fun.endswith('.start'):
|
||||||
logger.info("Starting '{0}' api module".format(fun))
|
logger.info("Starting '{0}' api module".format(fun))
|
||||||
multiprocessing.Process(target=netapi[fun]).start()
|
p = multiprocessing.Process(target=netapi[fun])
|
||||||
|
p.start()
|
||||||
|
self.processes.append(p)
|
||||||
|
|
||||||
|
# make sure to kill the subprocesses if the parent is killed
|
||||||
|
signal.signal(signal.SIGTERM, self.kill_children)
|
||||||
|
|
||||||
|
def kill_children(self, *args):
|
||||||
|
'''
|
||||||
|
Kill all of the children
|
||||||
|
'''
|
||||||
|
for p in self.processes:
|
||||||
|
p.terminate()
|
||||||
|
p.join()
|
||||||
|
Loading…
Reference in New Issue
Block a user