Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def restart(self):
""" Restart the supervisor process
@return boolean result always return True unless error
"""
self._update('restart')
self.supervisord.options.mood = SupervisorStates.RESTARTING
return True
def handle_signal(self):
sig = self.options.get_signal()
if sig:
if sig in (signal.SIGTERM, signal.SIGINT, signal.SIGQUIT):
self.options.logger.warn(
'received %s indicating exit request' % signame(sig))
self.options.mood = SupervisorStates.SHUTDOWN
elif sig == signal.SIGHUP:
self.options.logger.warn(
'received %s indicating restart request' % signame(sig))
self.options.mood = SupervisorStates.RESTARTING
elif sig == signal.SIGCHLD:
self.options.logger.debug(
'received %s indicating a child quit' % signame(sig))
elif sig == signal.SIGUSR2:
self.options.logger.info(
'received %s indicating log reopen request' % signame(sig))
self.options.reopenlogs()
for group in self.process_groups.values():
group.reopenlogs()
else:
self.options.logger.blather(
'received %s indicating nothing' % signame(sig))
def runforever(self):
events.notify(events.SupervisorRunningEvent())
timeout = 1 # this cannot be fewer than the smallest TickEvent (5)
socket_map = self.options.get_socket_map()
while 1:
combined_map = {}
combined_map.update(socket_map)
combined_map.update(self.get_process_map())
pgroups = list(self.process_groups.values())
pgroups.sort()
if self.options.mood < SupervisorStates.RUNNING:
if not self.stopping:
# first time, set the stopping flag, do a
# notification and set stop_groups
self.stopping = True
self.stop_groups = pgroups[:]
events.notify(events.SupervisorStoppingEvent())
self.ordered_stop_groups_phase_1()
if not self.shutdown_report():
# if there are no unstopped processes (we're done
# killing everything), it's OK to shutdown or reload
raise asyncore.ExitNow
for fd, dispatcher in combined_map.items():
if dispatcher.readable():
def _update(self, text):
self.update_text = text # for unit tests, mainly
if ( isinstance(self.supervisord.options.mood, int) and
self.supervisord.options.mood < SupervisorStates.RUNNING ):
raise RPCError(Faults.SHUTDOWN_STATE)
def shutdown(self):
""" Shut down the supervisor process
@return boolean result always returns True unless error
"""
self._update('shutdown')
self.supervisord.options.mood = SupervisorStates.SHUTDOWN
return True
def handle_signal(self):
sig = self.options.get_signal()
if sig:
if sig in (signal.SIGTERM, signal.SIGINT, signal.SIGQUIT):
self.options.logger.warn(
'received %s indicating exit request' % signame(sig))
self.options.mood = SupervisorStates.SHUTDOWN
elif sig == signal.SIGHUP:
if self.options.mood == SupervisorStates.SHUTDOWN:
self.options.logger.warn(
'ignored %s indicating restart request (shutdown in progress)' % signame(sig))
else:
self.options.logger.warn(
'received %s indicating restart request' % signame(sig))
self.options.mood = SupervisorStates.RESTARTING
elif sig == signal.SIGCHLD:
self.options.logger.debug(
'received %s indicating a child quit' % signame(sig))
elif sig == signal.SIGUSR2:
self.options.logger.info(
'received %s indicating log reopen request' % signame(sig))
self.options.reopenlogs()
for group in self.process_groups.values():
def _update(self, func_name):
self.update_text = func_name
state = self.supervisord.get_state()
if state == SupervisorStates.SHUTDOWN:
raise RPCError(SupervisorFaults.SHUTDOWN_STATE)
if len(self._whitelist):
if func_name not in self._whitelist:
raise RPCError(Faults.NOT_IN_WHITELIST, func_name)
def runforever(self):
events.notify(events.SupervisorRunningEvent())
timeout = 1 # this cannot be fewer than the smallest TickEvent (5)
socket_map = self.options.get_socket_map()
while 1:
combined_map = {}
combined_map.update(socket_map)
combined_map.update(self.get_process_map())
pgroups = self.process_groups.values()
pgroups.sort()
if self.options.mood < SupervisorStates.RUNNING:
if not self.stopping:
# first time, set the stopping flag, do a
# notification and set stop_groups
self.stopping = True
self.stop_groups = pgroups[:]
events.notify(events.SupervisorStoppingEvent())
self.ordered_stop_groups_phase_1()
if not self.shutdown_report():
# if there are no unstopped processes (we're done
# killing everything), it's OK to shutdown or reload
raise asyncore.ExitNow
r, w, x = [], [], []
def runforever(self):
events.notify(events.SupervisorRunningEvent())
timeout = 1 # this cannot be fewer than the smallest TickEvent (5)
socket_map = self.options.get_socket_map()
while 1:
combined_map = {}
combined_map.update(socket_map)
combined_map.update(self.get_process_map())
pgroups = self.process_groups.values()
pgroups.sort()
if self.options.mood < SupervisorStates.RUNNING:
if self.options.subprocpidfile:
# 'subprocpidfile' option is set, which implies that all
# managed sub-processes should NOT be killed and would
# continue to run even supervisord exits. the supervisord
# would also continue to manage these sub-processes after
# it restarts.
self.options.logger.info('exiting without killing managed '
'sub-processes')
raise asyncore.ExitNow
if not self.stopping:
# first time, set the stopping flag, do a
# notification and set stop_groups
self.stopping = True
self.stop_groups = pgroups[:]
events.notify(events.SupervisorStoppingEvent())
def handle_signal(self):
sig = self.options.get_signal()
if sig:
if sig in (signal.SIGTERM, signal.SIGINT, signal.SIGQUIT):
self.options.logger.warn(
'received %s indicating exit request' % signame(sig))
self.options.mood = SupervisorStates.SHUTDOWN
elif sig == signal.SIGHUP:
self.options.logger.warn(
'received %s indicating restart request' % signame(sig))
self.options.mood = SupervisorStates.RESTARTING
elif sig == signal.SIGCHLD:
self.options.logger.debug(
'received %s indicating a child quit' % signame(sig))
elif sig == signal.SIGUSR2:
self.options.logger.info(
'received %s indicating log reopen request' % signame(sig))
self.options.reopenlogs()
for group in self.process_groups.values():
group.reopenlogs()
else:
self.options.logger.blather(
'received %s indicating nothing' % signame(sig))