Browse Source

Stub out 'startretrysecs' and 'stopwaitsecs'.

Chris McDonough 19 years ago
parent
commit
31ab631aea
5 changed files with 37 additions and 11 deletions
  1. 14 1
      README.txt
  2. 1 3
      TODO.txt
  3. 15 4
      src/supervisor/options.py
  4. 1 2
      src/supervisor/supervisord.py
  5. 6 1
      src/supervisor/tests.py

+ 14 - 1
README.txt

@@ -290,8 +290,10 @@ Configuration File '[program:x]' Section Settings
     priority=1
     autostart=true
     autorestart=true
+    startretrysecs=10
     exitcodes=0,2
-    stopsignal=INT
+    stopsignal=TERM
+    stopwaitsecs=10
     user=nobody
     log_stderr=false
     logfile=/tmp/programname.log
@@ -325,6 +327,11 @@ Configuration File '[program:x]' Section Settings
   those which aren't as a result of a program exit with an "expected"
   exit code.  Default: true.
 
+  'startretrysecs' -- The total number of seconds spent attempting to
+  continually retry startup of the program due to a startup failure.
+  After this number of seconds, supervisord gives up and puts the
+  process into an ERROR state.  Default: 10.
+
   'exitcodes' -- The list of 'expected' exit codes for this program.
   Default: 0,2.
 
@@ -332,6 +339,12 @@ Configuration File '[program:x]' Section Settings
   requested.  This can be any of TERM, HUP, INT, QUIT, KILL, USR1, or
   USR2.  Default: TERM.
 
+  'stopwaitsecs' -- The number of seconds to wait for the program to
+  return a SIGCHILD to supervisord after the program has been sent a
+  stopsignal.  If this number of seconds elapses before supervisord
+  receives a SIGCHILD from the process, supervisord will attempt to
+  kill it with a final SIGKILL.  Default: 10.
+
   'user' -- If supervisord is running as root, this UNIX user account
   will be used as the account which runs the program.  If supervisord
   is not running as root, this option has no effect.  Defaut: do not

+ 1 - 3
TODO.txt

@@ -9,13 +9,11 @@
 
 - Rewrite the delay/backoff stuff so humans can understand it.
 
-- Move 'forever' and 'backofflimit' options into process config.
+- Make 'startretrysecs' and 'stopwaitsecs' "real".
 
 - If a process dies with an expected exit code but keeps dying, it
   will restart forever.
 
-- Subprocess: left off before spawn_as_parent tests.
-
 - Unit tests for meld classes and ui server.
 
 - Tail main log.

+ 15 - 4
src/supervisor/options.py

@@ -689,6 +689,8 @@ class ServerOptions(Options):
             autostart = datatypes.boolean(autostart)
             autorestart = config.saneget(section, 'autorestart', 'true')
             autorestart = datatypes.boolean(autorestart)
+            startretrysecs = config.saneget(section, 'startretrysecs', 10)
+            startretrysecs = datatypes.integer(startretrysecs)
             uid = config.saneget(section, 'user', None)
             if uid is not None:
                 uid = datatypes.name_to_uid(uid)
@@ -706,6 +708,8 @@ class ServerOptions(Options):
             logfile_maxbytes = datatypes.integer(logfile_maxbytes)
             stopsignal = config.saneget(section, 'stopsignal', signal.SIGTERM)
             stopsignal = datatypes.signal(stopsignal)
+            stopwaitsecs = config.saneget(section, 'stopwaitsecs', 10)
+            stopwaitsecs = datatypes.integer(stopwaitsecs)
             exitcodes = config.saneget(section, 'exitcodes', '0,2')
             try:
                 exitcodes = datatypes.list_of_ints(exitcodes)
@@ -714,12 +718,16 @@ class ServerOptions(Options):
             log_stderr = config.saneget(section, 'log_stderr', 'false')
             log_stderr = datatypes.boolean(log_stderr)
             pconfig = ProcessConfig(name=name, command=command,
-                                    priority=priority, autostart=autostart,
-                                    autorestart=autorestart, uid=uid,
+                                    priority=priority,
+                                    autostart=autostart,
+                                    autorestart=autorestart,
+                                    startretrysecs=startretrysecs,
+                                    uid=uid,
                                     logfile=logfile,
                                     logfile_backups=logfile_backups,
                                     logfile_maxbytes=logfile_maxbytes,
                                     stopsignal=stopsignal,
+                                    stopwaitsecs=stopwaitsecs,
                                     exitcodes=exitcodes,
                                     log_stderr=log_stderr)
             programs.append(pconfig)
@@ -1219,18 +1227,21 @@ class UnhosedConfigParser(ConfigParser.RawConfigParser):
 
 class ProcessConfig:
     def __init__(self, name, command, priority, autostart, autorestart,
-                 uid, logfile, logfile_backups, logfile_maxbytes, stopsignal,
-                 exitcodes, log_stderr):
+                 startretrysecs, uid, logfile, logfile_backups,
+                 logfile_maxbytes, stopsignal, stopwaitsecs, exitcodes,
+                 log_stderr):
         self.name = name
         self.command = command
         self.priority = priority
         self.autostart = autostart
         self.autorestart = autorestart
+        self.startretrysecs = startretrysecs
         self.uid = uid
         self.logfile = logfile
         self.logfile_backups = logfile_backups
         self.logfile_maxbytes = logfile_maxbytes
         self.stopsignal = stopsignal
+        self.stopwaitsecs = stopwaitsecs
         self.exitcodes = exitcodes
         self.log_stderr = log_stderr
 

+ 1 - 2
src/supervisor/supervisord.py

@@ -98,7 +98,7 @@ class Subprocess:
     backoff = 0 # backoff counter (to backofflimit)
     pipes = None # mapping of pipe descriptor purpose to file descriptor
     childlog = None # the current logger 
-    logbuffer = '' # buffer of characters read from child's stdout/stderr
+    logbuffer = '' # buffer of characters read from child pipes
     reportstatusmsg = None # message attached to instance during reportstatus()
     waitstatus = None
     exitstatus = None
@@ -596,7 +596,6 @@ class Supervisor:
                 proc.reportstatus()
 
     def handle_procs_with_delay(self):
-        delayprocs = []
         now = time.time()
         timeout = self.options.backofflimit
         processes = self.processes.values()

+ 6 - 1
src/supervisor/tests.py

@@ -69,6 +69,8 @@ autorestart=true
 user=root
 logfile=/tmp/cat.log
 stopsignal=KILL
+stopwaitsecs=5
+startretrysecs=5
 
 [program:cat2]
 command=/bin/cat
@@ -118,9 +120,11 @@ exitcodes=0,1,127
         self.assertEqual(cat.priority, 1)
         self.assertEqual(cat.autostart, True)
         self.assertEqual(cat.autorestart, True)
+        self.assertEqual(cat.startretrysecs, 5)
         self.assertEqual(cat.uid, 0)
         self.assertEqual(cat.logfile, '/tmp/cat.log')
         self.assertEqual(cat.stopsignal, signal.SIGKILL)
+        self.assertEqual(cat.stopwaitsecs, 5)
         self.assertEqual(cat.logfile_maxbytes, datatypes.byte_size('50MB'))
         self.assertEqual(cat.logfile_backups, 10)
         self.assertEqual(cat.exitcodes, [0,2])
@@ -2065,7 +2069,7 @@ class DummyPConfig:
     def __init__(self, name, command, priority=999, autostart=True,
                  autorestart=True, uid=None, logfile=None, logfile_backups=0,
                  logfile_maxbytes=0, log_stderr=False,
-                 stopsignal=signal.SIGTERM,
+                 stopsignal=signal.SIGTERM, stopwaitsecs=10,
                  exitcodes=[0,2]):
         self.name = name
         self.command = command
@@ -2078,6 +2082,7 @@ class DummyPConfig:
         self.logfile_maxbytes = logfile_maxbytes
         self.log_stderr = log_stderr
         self.stopsignal = stopsignal
+        self.stopwaitsecs = stopwaitsecs
         self.exitcodes = exitcodes