From 90acef9a309db8948f0a35a013a71dc260027b29 Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Mon, 7 Jan 2013 19:51:58 -0800 Subject: [PATCH 1/2] Quit child processes when supervisor crashes (Linux only) Use prctl(PR_SET_PDEATHSIG, SIGTERM) to send signal when parent dies --- supervisor/process.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/supervisor/process.py b/supervisor/process.py index a724b3ca8..b3eb470a7 100644 --- a/supervisor/process.py +++ b/supervisor/process.py @@ -23,6 +23,7 @@ from supervisor import events from supervisor.datatypes import RestartUnconditionally +from supervisor.datatypes import signal_number from supervisor.socket_manager import SocketManager @@ -284,6 +285,19 @@ def _spawn_as_child(self, filename, argv): # Presumably it also prevents HUP, etc received by # supervisord from being sent to children. options.setpgrp() + + # Send this process a stop signal if supervisor crashes. + # Uses system call prctl(PR_SET_PDEATHSIG, ). + # This will only work on Linux. + try: + import ctypes + import ctypes.util + libc = ctypes.cdll.LoadLibrary(ctypes.util.find_library('c')) + libc.prctl(1, signal_number(self.config.stopsignal)) + except Exception, e: + options.logger.debug("Could not set parent death signal. " + "This is expected if not running on Linux.") + self._prepare_child_fds() # sending to fd 2 will put this output in the stderr log msg = self.set_uid() From d32be887d04f496489bbf7616a91b5ea1f90696e Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Thu, 18 Apr 2013 18:03:47 -0700 Subject: [PATCH 2/2] ENG-8730 PDEATHSIG is SIGKILL instead of SIGTERM --- supervisor/process.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/supervisor/process.py b/supervisor/process.py index b3eb470a7..43d918cb4 100644 --- a/supervisor/process.py +++ b/supervisor/process.py @@ -286,14 +286,14 @@ def _spawn_as_child(self, filename, argv): # supervisord from being sent to children. options.setpgrp() - # Send this process a stop signal if supervisor crashes. + # Send this process a kill signal if supervisor crashes. # Uses system call prctl(PR_SET_PDEATHSIG, ). # This will only work on Linux. try: import ctypes import ctypes.util libc = ctypes.cdll.LoadLibrary(ctypes.util.find_library('c')) - libc.prctl(1, signal_number(self.config.stopsignal)) + libc.prctl(1, signal.SIGKILL) except Exception, e: options.logger.debug("Could not set parent death signal. " "This is expected if not running on Linux.")