Fix file paths for recursive rmdom
[hcoop/domtool2.git] / src / plugins / apache.sml
index 955e9d8..65ba7fb 100644 (file)
@@ -180,9 +180,11 @@ val autoindex_option = fn (EApp ((EVar "descriptionWidth", _), w), _) =>
                        | _ => NONE
 
 val vhostsChanged = ref false
+val logDeleted = ref false
 
 val () = Slave.registerPreHandler
-            (fn () => vhostsChanged := false)
+            (fn () => (vhostsChanged := false;
+                       logDeleted := false))
 
 fun findVhostUser fname =
     let
@@ -234,7 +236,12 @@ val () = Slave.registerFileHandler (fn fs =>
                                                       vhostsChanged := true;
                                                       case #action fs of
                                                           Slave.Delete =>
-                                                          (ignore (OS.Process.system (Config.rm
+                                                          (if !logDeleted then
+                                                               ()
+                                                           else
+                                                               (ignore (OS.Process.system Config.Apache.down);
+                                                                logDeleted := true);
+                                                           ignore (OS.Process.system (Config.rm
                                                                                       ^ " -rf "
                                                                                       ^ realVhostFile));
                                                            ignore (OS.Process.system (Config.rm
@@ -265,7 +272,7 @@ val () = Slave.registerFileHandler (fn fs =>
 val () = Slave.registerPostHandler
         (fn () =>
             (if !vhostsChanged then
-                 Slave.shellF ([Config.Apache.reload],
+                 Slave.shellF ([if !logDeleted then Config.Apache.undown else Config.Apache.reload],
                                fn cl => "Error reloading Apache with " ^ cl)
              else
                  ()))
@@ -732,4 +739,7 @@ val () = Env.action_one "readmeName"
                      write name;
                      write "\n"))
 
+val () = Domain.registerResetLocal (fn () =>
+                                      ignore (OS.Process.system (Config.rm ^ " -rf /var/domtool/vhosts/*")))
+
 end