Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a "restartpause" option #509

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion supervisor/options.py
Expand Up @@ -848,6 +848,7 @@ def get(section, opt, *args, **kwargs):
autorestart = auto_restart(get(section, 'autorestart', 'unexpected'))
startsecs = integer(get(section, 'startsecs', 1))
startretries = integer(get(section, 'startretries', 3))
restartpause = integer(get(section, 'restartpause', 0))
stopsignal = signal_number(get(section, 'stopsignal', 'TERM'))
stopwaitsecs = integer(get(section, 'stopwaitsecs', 10))
stopasgroup = boolean(get(section, 'stopasgroup', 'false'))
Expand Down Expand Up @@ -948,6 +949,7 @@ def get(section, opt, *args, **kwargs):
autorestart=autorestart,
startsecs=startsecs,
startretries=startretries,
restartpause=restartpause,
uid=uid,
stdout_logfile=logfiles['stdout_logfile'],
stdout_capture_maxbytes = stdout_cmaxbytes,
Expand Down Expand Up @@ -1711,7 +1713,7 @@ def __repr__(self):
class ProcessConfig(Config):
req_param_names = [
'name', 'uid', 'command', 'directory', 'umask', 'priority',
'autostart', 'autorestart', 'startsecs', 'startretries',
'autostart', 'autorestart', 'startsecs', 'startretries', 'restartpause',
'stdout_logfile', 'stdout_capture_maxbytes',
'stdout_events_enabled', 'stdout_syslog',
'stdout_logfile_backups', 'stdout_logfile_maxbytes',
Expand Down
7 changes: 5 additions & 2 deletions supervisor/process.py
Expand Up @@ -171,7 +171,7 @@ def change_state(self, new_state, expected=True):
if new_state == ProcessStates.BACKOFF:
now = time.time()
self.backoff += 1
self.delay = now + self.backoff
self.delay = now + self.backoff + self.config.restartpause

self.state = new_state

Expand Down Expand Up @@ -531,6 +531,9 @@ def finish(self, pid, sts):
# unexpected exit code
self.spawnerr = 'Bad exit code %s' % es
msg = "exited: %s (%s)" % (processname, msg + "; not expected")
self.delay = now + self.config.restartpause
if self.config.restartpause > 0:
msg += ". Will restart in %s seconds (restartpause)" % self.config.restartpause
self.change_state(ProcessStates.EXITED, expected=False)

self.config.options.logger.info(msg)
Expand Down Expand Up @@ -580,7 +583,7 @@ def transition(self):
if self.config.options.mood > SupervisorStates.RESTARTING:
# dont start any processes if supervisor is shutting down
if state == ProcessStates.EXITED:
if self.config.autorestart:
if self.config.autorestart and now > self.delay:
if self.config.autorestart is RestartUnconditionally:
# EXITED -> STARTING
self.spawn()
Expand Down