Merge pull request #49467 from rallytime/bp-49451

Back-port #49451 to 2018.3.3
This commit is contained in:
Nicole Thomas 2018-08-31 13:38:08 -04:00 committed by GitHub
commit 39fdacc434
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 19 deletions

View file

@ -112,6 +112,8 @@ def minion_process():
def handle_hup(manager, sig, frame):
manager.minion.reload()
lock = threading.RLock()
def suicide_when_without_parent(parent_pid):
'''
Have the minion suicide if the parent process is gone
@ -119,7 +121,8 @@ def minion_process():
NOTE: small race issue where the parent PID could be replace
with another process with same PID!
'''
while True:
while lock.acquire(blocking=False):
lock.release()
time.sleep(5)
try:
# check pid alive (Unix only trick!)
@ -131,18 +134,18 @@ def minion_process():
log.error('Minion process encountered exception: %s', exc)
os._exit(salt.defaults.exitcodes.EX_GENERIC)
if not salt.utils.platform.is_windows():
thread = threading.Thread(target=suicide_when_without_parent, args=(os.getppid(),))
thread.start()
minion = salt.cli.daemons.Minion()
signal.signal(signal.SIGHUP,
functools.partial(handle_hup,
minion))
try:
if not salt.utils.platform.is_windows():
thread = threading.Thread(target=suicide_when_without_parent, args=(os.getppid(),))
thread.start()
minion = salt.cli.daemons.Minion()
signal.signal(signal.SIGHUP,
functools.partial(handle_hup,
minion))
minion.start()
except (SaltClientError, SaltReqTimeoutError, SaltSystemExit) as exc:
lock.acquire(blocking=True)
log.warning('Fatal functionality error caught by minion handler:\n', exc_info=True)
log.warning('** Restarting minion **')
delay = 60
@ -152,6 +155,8 @@ def minion_process():
log.info('waiting random_reauth_delay %ss', delay)
time.sleep(delay)
sys.exit(salt.defaults.exitcodes.SALT_KEEPALIVE)
finally:
lock.acquire(blocking=True)
def salt_minion():
@ -240,6 +245,8 @@ def proxy_minion_process(queue):
import salt.utils.platform
# salt_minion spawns this function in a new process
lock = threading.RLock()
def suicide_when_without_parent(parent_pid):
'''
Have the minion suicide if the parent process is gone
@ -247,7 +254,8 @@ def proxy_minion_process(queue):
NOTE: there is a small race issue where the parent PID could be replace
with another process with the same PID!
'''
while True:
while lock.acquire(blocking=False):
lock.release()
time.sleep(5)
try:
# check pid alive (Unix only trick!)
@ -257,14 +265,14 @@ def proxy_minion_process(queue):
# isn't sufficient in a thread
os._exit(999)
if not salt.utils.platform.is_windows():
thread = threading.Thread(target=suicide_when_without_parent, args=(os.getppid(),))
thread.start()
restart = False
proxyminion = None
status = salt.defaults.exitcodes.EX_OK
try:
if not salt.utils.platform.is_windows():
thread = threading.Thread(target=suicide_when_without_parent, args=(os.getppid(),))
thread.start()
restart = False
proxyminion = None
status = salt.defaults.exitcodes.EX_OK
proxyminion = salt.cli.daemons.ProxyMinion()
proxyminion.start()
except (Exception, SaltClientError, SaltReqTimeoutError, SaltSystemExit) as exc:
@ -275,6 +283,8 @@ def proxy_minion_process(queue):
except SystemExit as exc:
restart = False
status = exc.code
finally:
lock.acquire(blocking=True)
if restart is True:
log.warning('** Restarting proxy minion **')

View file

@ -22,7 +22,10 @@
# Import python libs
from __future__ import absolute_import, unicode_literals, print_function
from collections import Callable
try:
from collections.abc import Callable
except ImportError:
from collections import Callable
# Import 3rd-party libs
from salt.ext import six