Преглед изворни кода

Provide restart all and stop all functionality in web UI.

Chris McDonough пре 19 година
родитељ
комит
9a740d2dc8
3 измењених фајлова са 43 додато и 2 уклоњено
  1. 8 2
      TODO.txt
  2. 8 0
      src/supervisor/ui/status.html
  3. 27 0
      src/supervisor/web.py

+ 8 - 2
TODO.txt

@@ -3,15 +3,21 @@
    - present status in addition to state (e.g. spawnerr, etc, same as
      supervisorctl)
 
-   - provide "restart all" functionality
+- Rewrite RPC stuff: use ProcessStates rather than direct attribute
+  access, rename methods to lower.
 
 - Unit tests for meld classes and ui server.
 
+- Use HTTP_HOST for generated URL names in web.py.
+
 - Unit tests for log rotation.
 
+- Better remote explanation when kill_undead needs to happen from
+  supervisorctl (long blockage).
+
 - Command-line arg tests.
 
-- supervisorctl command history
+- Log logtail requests.
 
 - stop logging all RPC requests in info mode when we ship
 

+ 8 - 0
src/supervisor/ui/status.html

@@ -51,6 +51,14 @@
    <input type="button" value=" Refresh " name="refresh" />
 </a>
 
+<a href="index.html?action=restartall">
+   <input type="button" value=" Restart All " name="restartall" />
+</a>
+
+<a href="index.html?action=stopall">
+   <input type="button" value=" Stop All " name="stopall" />
+</a>
+
 </div>
 
 </form>

+ 27 - 0
src/supervisor/web.py

@@ -123,6 +123,7 @@ class StatusView(MeldView):
             return 'statusnominal'
 
     def handle_query(self, query):
+        from supervisord import ProcessStates
         message = None
         supervisord = self.context.supervisord
 
@@ -138,6 +139,29 @@ class StatusView(MeldView):
             if action == 'refresh':
                 message = 'Page refreshed at %s' % t
 
+            if action in ('stopall', 'restartall'):
+                supervisord.stop_all()
+
+                processes = supervisord.processes.values()
+                while 1:
+                    running = [ p for p in processes if
+                                p.get_state() in (ProcessStates.RUNNING,
+                                                  ProcessStates.STOPPING) ]
+                    if running:
+                        # XXX busywait
+                        supervisord.give_up()
+                        supervisord.kill_undead()
+                        supervisord.reap()
+                        supervisord.handle_signal()
+                        time.sleep(.01)
+                    else:
+                        break
+                message = 'All stopped at %s' % t
+                if action == 'restartall':
+                    for process in processes:
+                        process.spawn()
+                    message = 'All restarting at %s' % t
+
             elif processname:
                 process = supervisord.processes.get(processname)
                 if process is None:
@@ -154,6 +178,8 @@ class StatusView(MeldView):
                                 supervisord.give_up()
                                 supervisord.kill_undead()
                                 supervisord.reap()
+                                supervisord.handle_signal()
+                                time.sleep(.01)
                             process.spawn()
                             message = 'Restarted %s at %s' % (processname, t)
                         else:
@@ -165,6 +191,7 @@ class StatusView(MeldView):
                         supervisord.give_up()
                         supervisord.kill_undead()
                         supervisord.reap()
+                        supervisord.handle_signal()
                         message = 'Started %s at %s' % (processname, t)
                     if action == 'clearlog':
                         process.removelogs()