MCPcopy Create free account
hub / github.com/saltstack/salt / proxy_minion_process

Function proxy_minion_process

salt/scripts.py:317–388  ·  view source on GitHub ↗

Start a proxy minion process

(queue)

Source from the content-addressed store, hash-verified

315
316
317def proxy_minion_process(queue):
318 """
319 Start a proxy minion process
320 """
321 import salt.cli.daemons
322 import salt.utils.platform
323
324 # salt_minion spawns this function in a new process
325
326 lock = threading.RLock()
327
328 def suicide_when_without_parent(parent_pid):
329 """
330 Have the minion suicide if the parent process is gone
331
332 NOTE: there is a small race issue where the parent PID could be replace
333 with another process with the same PID!
334 """
335 while lock.acquire(blocking=False):
336 lock.release()
337 time.sleep(5)
338 try:
339 # check pid alive (Unix only trick!)
340 os.kill(parent_pid, 0)
341 except OSError:
342 # forcibly exit, regular sys.exit raises an exception-- which
343 # isn't sufficient in a thread
344 os._exit(999)
345
346 try:
347 if not salt.utils.platform.is_windows():
348 thread = threading.Thread(
349 target=suicide_when_without_parent, args=(os.getppid(),)
350 )
351 thread.start()
352
353 restart = False
354 proxyminion = None
355 status = salt.defaults.exitcodes.EX_OK
356 proxyminion = salt.cli.daemons.ProxyMinion()
357 proxyminion.start()
358 # pylint: disable=broad-except
359 except (
360 Exception,
361 SaltClientError,
362 SaltReqTimeoutError,
363 SaltSystemExit,
364 ) as exc:
365 # pylint: enable=broad-except
366 log.error("Proxy Minion failed to start: ", exc_info=True)
367 restart = True
368 # status is superfluous since the process will be restarted
369 status = salt.defaults.exitcodes.SALT_KEEPALIVE
370 except SystemExit as exc:
371 restart = False
372 status = exc.code
373 finally:
374 lock.acquire(blocking=True)

Callers

nothing calls this directly

Calls 9

startMethod · 0.95
warningMethod · 0.80
exitMethod · 0.80
startMethod · 0.45
errorMethod · 0.45
acquireMethod · 0.45
getMethod · 0.45
infoMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected