Proper handling of Apache log file deletion while Apache might have that file open
authorAdam Chlipala <adamc@hcoop.net>
Fri, 15 Dec 2006 22:40:58 +0000 (22:40 +0000)
committerAdam Chlipala <adamc@hcoop.net>
Fri, 15 Dec 2006 22:40:58 +0000 (22:40 +0000)
configDefault/apache.cfg
configDefault/apache.csg
scripts/domtool-publish
src/plugins/apache.sml

index 0000104..e1e7883 100644 (file)
@@ -1,6 +1,8 @@
 structure Apache :> APACHE_CONFIG = struct
 
 val reload = "/usr/bin/sudo /usr/local/sbin/domtool-publish apache"
+val down = "/usr/bin/sudo /usr/local/sbin/domtool-publish apache-down"
+val undown = "/usr/bin/sudo /usr/local/sbin/domtool-publish apache-undown"
 
 val confDir = "/var/domtool/vhosts"
 
index 307a47a..28188ac 100644 (file)
@@ -1,6 +1,8 @@
 signature APACHE_CONFIG = sig
 
     val reload : string
+    val        down : string
+    val        undown : string
 
     val confDir : string
 
index 60f3f27..fad7e85 100755 (executable)
@@ -5,6 +5,13 @@ case $1 in
                /usr/bin/rsync -r --delete /var/domtool/vhosts/ /etc/apache2/vhosts/
                /etc/init.d/apache2 reload
        ;;
+       apache-down)
+               /etc/init.d/apache2 stop
+       ;;
+       apache-undown)
+               /usr/bin/rsync -r --delete /var/domtool/vhosts/ /etc/apache2/vhosts/
+               /etc/init.d/apache2 start
+       ;;
        bind)
                /usr/bin/rsync -r --delete /var/domtool/zones/ /etc/bind/zones/
                /bin/cp /var/domtool/named.conf.local /etc/bind/
index 955e9d8..83a8ce8 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
                  ()))