소스 검색

stopasgroup implies killasgroup

Roger Hoover 13 년 전
부모
커밋
1835280d89
2개의 변경된 파일38개의 추가작업 그리고 3개의 파일을 삭제
  1. 5 1
      supervisor/options.py
  2. 33 2
      supervisor/tests/test_options.py

+ 5 - 1
supervisor/options.py

@@ -751,7 +751,7 @@ class ServerOptions(Options):
         stopsignal = signal_number(get(section, 'stopsignal', 'TERM'))
         stopwaitsecs = integer(get(section, 'stopwaitsecs', 10))
         stopasgroup = boolean(get(section, 'stopasgroup', 'false'))
-        killasgroup = boolean(get(section, 'killasgroup', 'false'))
+        killasgroup = boolean(get(section, 'killasgroup', stopasgroup))
         exitcodes = list_of_exitcodes(get(section, 'exitcodes', '0,2'))
         redirect_stderr = boolean(get(section, 'redirect_stderr','false'))
         numprocs = integer(get(section, 'numprocs', 1))
@@ -783,6 +783,10 @@ class ServerOptions(Options):
                 raise ValueError(
                     '%(process_num) must be present within process_name when '
                     'numprocs > 1')
+                    
+        if stopasgroup and not killasgroup:
+            raise ValueError("Cannot set stopasgroup=true and killasgroup=false")
+
         host_node_name = platform.node()
         for process_num in range(numprocs_start, numprocs + numprocs_start):
             expansions = {'here':self.here,

+ 33 - 2
supervisor/tests/test_options.py

@@ -634,7 +634,6 @@ class ServerOptionsTests(unittest.TestCase):
         stdout_events_enabled = true
         stopsignal = KILL
         stopwaitsecs = 100
-        stopasgroup = true
         killasgroup = true
         exitcodes = 1,4
         redirect_stderr = false
@@ -660,7 +659,7 @@ class ServerOptionsTests(unittest.TestCase):
         self.assertEqual(pconfig.stdout_logfile_maxbytes, 104857600)
         self.assertEqual(pconfig.stdout_events_enabled, True)
         self.assertEqual(pconfig.stopsignal, signal.SIGKILL)
-        self.assertEqual(pconfig.stopasgroup, True)
+        self.assertEqual(pconfig.stopasgroup, False)
         self.assertEqual(pconfig.killasgroup, True)
         self.assertEqual(pconfig.stopwaitsecs, 100)
         self.assertEqual(pconfig.exitcodes, [1,4])
@@ -746,6 +745,38 @@ class ServerOptionsTests(unittest.TestCase):
         self.assertRaises(ValueError, instance.processes_from_section,
                           config, 'program:foo', None)
 
+    def test_processes_from_section_stopasgroup_implies_killasgroup(self):
+        instance = self._makeOne()
+        text = lstrip("""\
+        [program:foo]
+        command = /bin/cat
+        process_name = %(program_name)s
+        stopasgroup = true
+        """)
+        from supervisor.options import UnhosedConfigParser
+        config = UnhosedConfigParser()
+        config.read_string(text)
+        pconfigs = instance.processes_from_section(config, 'program:foo', 'bar')
+        self.assertEqual(len(pconfigs), 1)
+        pconfig = pconfigs[0]
+        self.assertEqual(pconfig.stopasgroup, True)
+        self.assertEqual(pconfig.killasgroup, True)
+    
+    def test_processes_from_section_killasgroup_mismatch_w_stopasgroup(self):
+        instance = self._makeOne()
+        text = lstrip("""\
+        [program:foo]
+        command = /bin/cat
+        process_name = %(program_name)s
+        stopasgroup = true
+        killasgroup = false
+        """)
+        from supervisor.options import UnhosedConfigParser
+        config = UnhosedConfigParser()
+        config.read_string(text)
+        self.assertRaises(ValueError, instance.processes_from_section,
+                          config, 'program:foo', None)
+
     def test_processes_from_autolog_without_rollover(self):
         instance = self._makeOne()
         text = lstrip("""\