[Zope3-checkins] SVN: Zope3/trunk/ Fixed bug 485: ServerControlForm.html / Restart, Shutdown does not work. This

Christian Theune ct at gocept.com
Fri Dec 2 13:58:02 EST 2005


Log message for revision 40500:
  Fixed bug 485: ServerControlForm.html / Restart, Shutdown does not work. This
  uses twisted's reactor now, implements the countdown feature and provides
  sensible user feedback with a real page.
  
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/app/applicationcontrol/browser/configure.zcml
  D   Zope3/trunk/src/zope/app/applicationcontrol/browser/server-control.pt
  A   Zope3/trunk/src/zope/app/applicationcontrol/browser/servercontrol.pt
  U   Zope3/trunk/src/zope/app/applicationcontrol/browser/servercontrol.py
  U   Zope3/trunk/src/zope/app/applicationcontrol/browser/tests/test_servercontrolview.py
  U   Zope3/trunk/src/zope/app/twisted/main.py
  U   Zope3/trunk/src/zope/app/twisted/servercontrol.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2005-12-02 18:54:37 UTC (rev 40499)
+++ Zope3/trunk/doc/CHANGES.txt	2005-12-02 18:58:00 UTC (rev 40500)
@@ -162,6 +162,10 @@
 
     Bug Fixes
 
+      - Fixed bug 485: ServerControlForm.html / Restart, Shutdown does not
+        work. This uses twisted's reactor now, implements the countdown
+        feature and provides sensible user feedback with a real page.
+
       - Fixed bugs 468 and 443: Invalid escaping of xml/html data on ZPT pages
         and text/* files.
 

Modified: Zope3/trunk/src/zope/app/applicationcontrol/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/applicationcontrol/browser/configure.zcml	2005-12-02 18:54:37 UTC (rev 40499)
+++ Zope3/trunk/src/zope/app/applicationcontrol/browser/configure.zcml	2005-12-02 18:58:00 UTC (rev 40500)
@@ -2,15 +2,13 @@
    xmlns:zope="http://namespaces.zope.org/zope"
    xmlns="http://namespaces.zope.org/browser">
 
-  <pages
+   <page
       for="zope.app.applicationcontrol.interfaces.IApplicationControl"
-      permission="zope.ManageApplication"
-      class=".servercontrol.ServerControlView">
+      name="servercontrol.html"
+      template="servercontrol.pt"
+      class=".servercontrol.ServerControlView"
+      permission="zope.ManageApplication"/>
 
-    <page name="ServerControlForm.html" template="server-control.pt" />
-    <page name="ServerControl.html" attribute="action" />
-  </pages>
-
    <page
       for="zope.app.applicationcontrol.interfaces.IApplicationControl"
       name="index.html"
@@ -29,7 +27,7 @@
     <menuItem
         order="-1"
         title="Server Control"
-        action="ServerControlForm.html" />
+        action="servercontrol.html" />
   </menuItems>
 
   <page

Deleted: Zope3/trunk/src/zope/app/applicationcontrol/browser/server-control.pt
===================================================================
--- Zope3/trunk/src/zope/app/applicationcontrol/browser/server-control.pt	2005-12-02 18:54:37 UTC (rev 40499)
+++ Zope3/trunk/src/zope/app/applicationcontrol/browser/server-control.pt	2005-12-02 18:58:00 UTC (rev 40500)
@@ -1,35 +0,0 @@
-<html metal:use-macro="context/@@standard_macros/view" i18n:domain="zope">
-<head>
-  <title i18n:translate="">Zope Stub Server Controller</title>
-</head>
-<body>
-<div metal:fill-slot="body">
-
-  <form name="servercontrol" action="ServerControl.html" method="post">
-    <div class="row">
-        <div class="label"
-            i18n:translate="">Shutdown time</div>
-        <div class="field">
-            <input type="text" name="time:int" size="5" value="0" />
-            &nbsp;<span i18n:translate="">seconds</span>
-            <p i18n:translate="">
-              If you specify a time of 0 seconds, then the server
-              will do a hard shutdown.
-            </p>
-        </div>
-    </div>
-
-    <div class="row">
-        <div class="controls">
-            <input type="submit" name="restart" value="Restart server" 
-                i18n:attributes="value" />
-            &nbsp;
-            <input type="submit" name="shutdown" value="Shutdown server" 
-                i18n:attributes="value" />
-        </div>
-    </div>
-  </form>
-
-</div>
-</body>
-</html>

Copied: Zope3/trunk/src/zope/app/applicationcontrol/browser/servercontrol.pt (from rev 40465, Zope3/trunk/src/zope/app/applicationcontrol/browser/server-control.pt)
===================================================================
--- Zope3/trunk/src/zope/app/applicationcontrol/browser/server-control.pt	2005-12-02 12:10:29 UTC (rev 40465)
+++ Zope3/trunk/src/zope/app/applicationcontrol/browser/servercontrol.pt	2005-12-02 18:58:00 UTC (rev 40500)
@@ -0,0 +1,41 @@
+<html metal:use-macro="context/@@standard_macros/view" i18n:domain="zope">
+<head>
+  <title i18n:translate="">Zope Stub Server Controller</title>
+</head>
+<body>
+<div metal:fill-slot="body">
+
+  <div class="message" 
+    tal:define="status view/action"
+    tal:condition="status"
+    tal:content="status">
+   </div>
+
+  <form name="servercontrol" action="servercontrol.html" method="post">
+    <div class="row">
+        <div class="label"
+            i18n:translate="">Countdown until restart or shutdown</div>
+        <div class="field">
+            <input type="text" name="time:int" size="5" value="0" />
+            &nbsp;<span i18n:translate="">seconds</span>
+            <p i18n:translate="">
+              If you specify a time of 0 seconds, then the server
+              will be shutdown or restarted immediately.
+            </p>
+        </div>
+    </div>
+
+    <div class="row">
+        <div class="controls">
+            <input type="submit" name="restart" value="Restart server" 
+                i18n:attributes="value" />
+            &nbsp;
+            <input type="submit" name="shutdown" value="Shutdown server" 
+                i18n:attributes="value" />
+        </div>
+    </div>
+  </form>
+
+</div>
+</body>
+</html>

Modified: Zope3/trunk/src/zope/app/applicationcontrol/browser/servercontrol.py
===================================================================
--- Zope3/trunk/src/zope/app/applicationcontrol/browser/servercontrol.py	2005-12-02 18:54:37 UTC (rev 40499)
+++ Zope3/trunk/src/zope/app/applicationcontrol/browser/servercontrol.py	2005-12-02 18:58:00 UTC (rev 40500)
@@ -27,11 +27,18 @@
     def serverControl(self):
         return zapi.getUtility(IServerControl)
 
-    def action(self, time=0):
+    def action(self):
         """Do the shutdown/restart!"""
+        # XXX I18N the responses
+        control = self.serverControl()
+
+        if 'time' in self.request:
+            time = self.request.get('time', 0)
+
         if 'restart' in self.request:
-            return (self.serverControl().restart(time)
-                    or _(u"You restarted the server."))
+            control.restart(time)
+            return u"The server will be restarted in %s seconds." % time
         elif 'shutdown' in self.request:
-            return (self.serverControl().shutdown(time)
-                    or _(u"You shut down the server."))
+            control.shutdown(time)
+            return u"The server will be shutdown in %s seconds." % time
+

Modified: Zope3/trunk/src/zope/app/applicationcontrol/browser/tests/test_servercontrolview.py
===================================================================
--- Zope3/trunk/src/zope/app/applicationcontrol/browser/tests/test_servercontrolview.py	2005-12-02 18:54:37 UTC (rev 40499)
+++ Zope3/trunk/src/zope/app/applicationcontrol/browser/tests/test_servercontrolview.py	2005-12-02 18:58:00 UTC (rev 40500)
@@ -50,16 +50,18 @@
 
         test_serverctrl = self._TestView__newView(
             applicationController,
-            {'shutdown': 1},
+            {'shutdown': 1,
+             'time': 100},
             )
-        test_serverctrl.action(100)
+        test_serverctrl.action()
         self.assertEqual(control.did_shutdown, 100)
 
         test_serverctrl = self._TestView__newView(
             applicationController,
-            {'restart': 1},
+            {'restart': 1,
+             'time': 100},
             )
-        test_serverctrl.action(100)
+        test_serverctrl.action()
         self.assertEqual(control.did_restart, 100)
 
 

Modified: Zope3/trunk/src/zope/app/twisted/main.py
===================================================================
--- Zope3/trunk/src/zope/app/twisted/main.py	2005-12-02 18:54:37 UTC (rev 40499)
+++ Zope3/trunk/src/zope/app/twisted/main.py	2005-12-02 18:58:00 UTC (rev 40500)
@@ -36,6 +36,11 @@
 
 CONFIG_FILENAME = "zope.conf"
 
+RESTART_ON_SHUTDOWN = False # We need some out-of-band communication between 
+                            # twisteds reactor and the zdaemon.
+                            # XXX ctheune: Can someone verify that this isn't 
+                            # totally ugly?
+
 class ZopeOptions(zdoptions.ZDOptions):
 
     logsectionname = None
@@ -61,6 +66,7 @@
 
 
 def main(args=None):
+    global RESTART_ON_SHUTDOWN
     # Record start times (real time and CPU time)
     t0 = time.time()
     c0 = time.clock()
@@ -74,9 +80,13 @@
     logging.info("Startup time: %.3f sec real, %.3f sec CPU", t1-t0, c1-c0)
 
     reactor.run()
-    sys.exit(0)
 
+    if RESTART_ON_SHUTDOWN:
+        sys.exit(1)
+    else:
+        sys.exit(0)
 
+
 def debug(args=None):
     options = load_options(args)
 

Modified: Zope3/trunk/src/zope/app/twisted/servercontrol.py
===================================================================
--- Zope3/trunk/src/zope/app/twisted/servercontrol.py	2005-12-02 18:54:37 UTC (rev 40499)
+++ Zope3/trunk/src/zope/app/twisted/servercontrol.py	2005-12-02 18:58:00 UTC (rev 40500)
@@ -15,30 +15,28 @@
 
 $Id$
 """
-from ThreadedAsync import LoopCallback
+
+from twisted.internet import reactor
+
 from zope.app.applicationcontrol.interfaces import IServerControl
+from zope.app.twisted import main
 from zope.interface import implements
 
+
 class ServerControl(object):
 
     implements(IServerControl)
 
     def shutdown(self, time=0):
         """See zope.app.applicationcontrol.interfaces.IServerControl"""
-        # TODO: Graceful shutdown does not work yet.
+        # This will work for servers started directly and by zdaemon.
+        reactor.callLater(time, reactor.stop)
 
-        # This will work for servers started directly and by zdaemon. Passing
-        # an exit status of 0 causes zdaemon to not restart the process.
-        LoopCallback.exit_status = 0
-
     def restart(self, time=0):
         """See zope.app.applicationcontrol.interfaces.IServerControl"""
-        # TODO: Graceful restart does not work yet.
-
         # TODO: Make sure this is only called if we are running via zdaemon.
+        # Setting the module global variable in the main module signals zdaemon to restart
+        main.RESTART_ON_SHUTDOWN = True
+        reactor.callLater(time, reactor.stop)
 
-        # Passing an exit status of 1 causes zdaemon to restart the process.
-        LoopCallback.exit_status = 1
-
-
 serverControl = ServerControl()



More information about the Zope3-Checkins mailing list