Added a way to properly shut down the SCGI server.
[jsvc.git] / src / dolda / jsvc / scgi / DirServer.java
index 7920977..d238504 100644 (file)
@@ -24,7 +24,7 @@ public class DirServer extends Server {
            String act = "loaded %s as %s";
            if(ctx != null) {
                if(ctx.mtime < file.lastModified()) {
-                   ctx.tg.destroy();
+                   ctx.tg.shutdown();
                    contexts.remove(file);
                    ctx = null;
                    act = "reloaded %s as %s";
@@ -51,6 +51,17 @@ public class DirServer extends Server {
        RequestThread w = ctx.tg.respond(req);
        w.start();
     }
+    
+    protected void shutdown() {
+       synchronized(contexts) {
+           for(Iterator<Map.Entry<File, DSContext>> i = contexts.entrySet().iterator(); i.hasNext();) {
+               Map.Entry<File, DSContext> e = i.next();
+               DSContext ctx = e.getValue();
+               i.remove();
+               ctx.tg.shutdown();
+           }
+       }
+    }
 
     private static void usage(PrintStream out) {
        out.println("usage: dolda.jsvc.scgi.DirServer [-h] [-e CHARSET] [-d DATADIR] PORT");