From: Adam Chlipala Date: Fri, 15 Dec 2006 22:40:58 +0000 (+0000) Subject: Proper handling of Apache log file deletion while Apache might have that file open X-Git-Tag: release_2010-11-19~298 X-Git-Url: https://git.hcoop.net/hcoop/domtool2.git/commitdiff_plain/8e965b2da49aab1faef95b25471513498ceca895 Proper handling of Apache log file deletion while Apache might have that file open --- diff --git a/configDefault/apache.cfg b/configDefault/apache.cfg index 0000104..e1e7883 100644 --- a/configDefault/apache.cfg +++ b/configDefault/apache.cfg @@ -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" diff --git a/configDefault/apache.csg b/configDefault/apache.csg index 307a47a..28188ac 100644 --- a/configDefault/apache.csg +++ b/configDefault/apache.csg @@ -1,6 +1,8 @@ signature APACHE_CONFIG = sig val reload : string + val down : string + val undown : string val confDir : string diff --git a/scripts/domtool-publish b/scripts/domtool-publish index 60f3f27..fad7e85 100755 --- a/scripts/domtool-publish +++ b/scripts/domtool-publish @@ -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/ diff --git a/src/plugins/apache.sml b/src/plugins/apache.sml index 955e9d8..83a8ce8 100644 --- a/src/plugins/apache.sml +++ b/src/plugins/apache.sml @@ -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 ()))