From c17d0537db6e55a6b2bbd1a459542a5fbb44a68f Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sat, 17 Nov 2007 17:34:44 +0000 Subject: [PATCH] Proper backing up of Apache logs --- configDefault/apache.cfg | 2 ++ configDefault/apache.csg | 2 ++ scripts/domtool-publish | 6 ++++++ src/plugins/apache.sml | 14 ++++++++++---- src/slave.sig | 1 - src/slave.sml | 11 +++-------- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/configDefault/apache.cfg b/configDefault/apache.cfg index 7f6648a..f2b9918 100644 --- a/configDefault/apache.cfg +++ b/configDefault/apache.cfg @@ -5,10 +5,12 @@ open ConfigTypes 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 fixperms = "/usr/bin/sudo /usr/local/sbin/domtool-publish apache-fixperms" val reload1 = "/usr/bin/sudo /usr/local/sbin/domtool-publish apache1.3" val down1 = "/usr/bin/sudo /usr/local/sbin/domtool-publish apache1.3-down" val undown1 = "/usr/bin/sudo /usr/local/sbin/domtool-publish apache1.3-undown" +val fixperms1 = "/usr/bin/sudo /usr/local/sbin/domtool-publish apache1.3-fixperms" val confDir = "/var/domtool/vhosts" diff --git a/configDefault/apache.csg b/configDefault/apache.csg index 6e20dbd..0e827e7 100644 --- a/configDefault/apache.csg +++ b/configDefault/apache.csg @@ -3,10 +3,12 @@ signature APACHE_CONFIG = sig val reload : string val down : string val undown : string + val fixperms : string val reload1 : string val down1 : string val undown1 : string + val fixperms1 : string val confDir : string diff --git a/scripts/domtool-publish b/scripts/domtool-publish index f3bd15d..3dce23a 100755 --- a/scripts/domtool-publish +++ b/scripts/domtool-publish @@ -66,6 +66,12 @@ case $1 in smtplog) /bin/grep $2 /var/log/exim4/mainlog ;; + apache-fixperms) + /bin/chown -R domtool.domtool /var/log/apache2/user + ;; + apache1.3-fixperms) + /bin/chown -R domtool.domtool /var/log/apache/user + ;; *) echo "Usage: domtool-publish [apache|bind|courier|exim|mailman|smtplog STRING]" ;; diff --git a/src/plugins/apache.sml b/src/plugins/apache.sml index 1f0fe83..4e07e4e 100644 --- a/src/plugins/apache.sml +++ b/src/plugins/apache.sml @@ -236,6 +236,7 @@ fun isWaklog node = fun down () = if imVersion1 () then Config.Apache.down1 else Config.Apache.down fun undown () = if imVersion1 () then Config.Apache.undown1 else Config.Apache.undown fun reload () = if imVersion1 () then Config.Apache.reload1 else Config.Apache.reload +fun fixperms () = if imVersion1 () then Config.Apache.fixperms1 else Config.Apache.fixperms fun logDir {user, node, vhostId} = String.concat [Config.Apache.logDirOf (isVersion1 node) user, @@ -271,6 +272,12 @@ val () = Slave.registerFileHandler (fn fs => logDir {user = valOf user, node = Slave.hostname (), vhostId = vhostId} + + fun backupLogs () = + OS.Path.joinDirFile + {dir = Config.Apache.backupLogDirOf + (isVersion1 (Slave.hostname ())), + file = vhostId} in vhostsChanged := true; case #action fs of @@ -282,13 +289,13 @@ val () = Slave.registerFileHandler (fn fs => () else (ignore (OS.Process.system (down ())); + ignore (OS.Process.system (fixperms ())); logDeleted := true); ignore (OS.Process.system (Config.rm ^ " -rf " ^ realVhostFile)); Slave.moveDirCreate {from = ldir, - to = Config.Apache.backupLogDirOf - (isVersion1 (Slave.hostname ()))} + to = backupLogs ()} end | Slave.Add => let @@ -302,8 +309,7 @@ val () = Slave.registerFileHandler (fn fs => if Posix.FileSys.access (rld, []) then () else - Slave.moveDirCreate {from = Config.Apache.backupLogDirOf - (isVersion1 (Slave.hostname ())), + Slave.moveDirCreate {from = backupLogs (), to = rld} end diff --git a/src/slave.sig b/src/slave.sig index 86c64fd..9ca0638 100644 --- a/src/slave.sig +++ b/src/slave.sig @@ -74,6 +74,5 @@ signature SLAVE = sig val remove : ''a list * ''a -> ''a list val removeDups : ''a list -> ''a list - val copyDirCreate : { from : string, to : string } -> unit val moveDirCreate : { from : string, to : string } -> unit end diff --git a/src/slave.sml b/src/slave.sml index 7a507fa..3262b52 100644 --- a/src/slave.sml +++ b/src/slave.sml @@ -209,17 +209,12 @@ fun removeDups ls = List.foldr (fn (x, ls) => else x :: ls) [] ls -fun copyDirCreate {from, to} = - (mkDirAll to; - if Posix.FileSys.access (from, []) then - ignore (OS.Process.system ("cp -r " ^ from ^ " " ^ to)) - else - ()) - fun moveDirCreate {from, to} = (mkDirAll to; if Posix.FileSys.access (from, []) then - ignore (OS.Process.system ("mv " ^ from ^ " " ^ to)) + (ignore (OS.Process.system ("rm -rf " ^ to)); + ignore (OS.Process.system ("cp -r " ^ from ^ " " ^ to)); + ignore (OS.Process.system ("rm -rf " ^ from))) else ()) -- 2.20.1