[tor-commits] [onionoo/master] Implement maintenance mode.

karsten at torproject.org karsten at torproject.org
Tue Apr 9 07:40:35 UTC 2013


commit 69993b96a1aeb49a9095de67df5ccc561a7e4e90
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Tue Apr 9 09:39:56 2013 +0200

    Implement maintenance mode.
    
    When set, respond to all requests with 503 Service Unavailable.
---
 etc/web.xml.template                            |    4 +++
 src/org/torproject/onionoo/ResourceServlet.java |   25 ++++++++++++++++++----
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/etc/web.xml.template b/etc/web.xml.template
index b7fbf9e..25314aa 100644
--- a/etc/web.xml.template
+++ b/etc/web.xml.template
@@ -15,6 +15,10 @@
       <param-name>outDir</param-name>
       <param-value>/srv/onionoo/out/</param-value>
     </init-param>
+    <init-param>
+      <param-name>maintenance</param-name>
+      <param-value>0</param-value>
+    </init-param>
   </servlet>
   <servlet-mapping>
     <servlet-name>Resource</servlet-name>
diff --git a/src/org/torproject/onionoo/ResourceServlet.java b/src/org/torproject/onionoo/ResourceServlet.java
index 19dc752..8c88781 100644
--- a/src/org/torproject/onionoo/ResourceServlet.java
+++ b/src/org/torproject/onionoo/ResourceServlet.java
@@ -31,15 +31,21 @@ public class ResourceServlet extends HttpServlet {
 
   private static final long serialVersionUID = 7236658979947465319L;
 
+  private boolean maintenanceMode = false;
+
   private File summaryFile;
 
   private String outDirString;
 
   public void init(ServletConfig config) throws ServletException {
     super.init(config);
-    this.outDirString = config.getInitParameter("outDir");
-    this.summaryFile = new File(outDirString, "summary");
-    this.readSummaryFile();
+    this.maintenanceMode = config.getInitParameter("maintenance") != null
+        && config.getInitParameter("maintenance").equals("1");
+    if (!this.maintenanceMode) {
+      this.outDirString = config.getInitParameter("outDir");
+      this.summaryFile = new File(outDirString, "summary");
+      this.readSummaryFile();
+    }
   }
 
   long summaryFileLastModified = -1L;
@@ -168,13 +174,22 @@ public class ResourceServlet extends HttpServlet {
   }
 
   public long getLastModified(HttpServletRequest request) {
-    this.readSummaryFile();
-    return this.summaryFileLastModified;
+    if (this.maintenanceMode) {
+      return super.getLastModified(request);
+    } else {
+      this.readSummaryFile();
+      return this.summaryFileLastModified;
+    }
   }
 
   public void doGet(HttpServletRequest request,
       HttpServletResponse response) throws IOException, ServletException {
 
+    if (this.maintenanceMode) {
+      response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
+      return;
+    }
+
     this.readSummaryFile();
     if (!this.readSummaryFile) {
       response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);



More information about the tor-commits mailing list