From 31b50af0d7e9779f3b0bd3f67acfc9104512a39d Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sat, 17 Nov 2007 16:48:41 +0000 Subject: [PATCH] Testing log directory backup --- configDefault/apache.cfg | 6 ++++++ configDefault/apache.csg | 1 + src/plugins/apache.sml | 30 ++++++++++++++++++------------ src/slave.sig | 3 +++ src/slave.sml | 14 ++++++++++++++ 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/configDefault/apache.cfg b/configDefault/apache.cfg index d7f90c3..7f6648a 100644 --- a/configDefault/apache.cfg +++ b/configDefault/apache.cfg @@ -37,4 +37,10 @@ fun logDirOf version1 user = user, "/apache/log"] +fun backupLogDirOf version1 = + if version1 then + "/afs/hcoop.net/common/etc/domtool/backup/apache/" + else + "/afs/hcoop.net/common/etc/domtool/backup/apache2/" + end diff --git a/configDefault/apache.csg b/configDefault/apache.csg index cd0fbb7..6e20dbd 100644 --- a/configDefault/apache.csg +++ b/configDefault/apache.csg @@ -19,5 +19,6 @@ signature APACHE_CONFIG = sig val public_html : string val logDirOf : bool -> string -> string + val backupLogDirOf : bool -> string end diff --git a/src/plugins/apache.sml b/src/plugins/apache.sml index be0e4f2..1f0fe83 100644 --- a/src/plugins/apache.sml +++ b/src/plugins/apache.sml @@ -275,17 +275,21 @@ val () = Slave.registerFileHandler (fn fs => vhostsChanged := true; case #action fs of Slave.Delete => - (if !logDeleted then - () - else - (ignore (OS.Process.system (down ())); - logDeleted := true); - ignore (OS.Process.system (Config.rm - ^ " -rf " - ^ realVhostFile)); - ignore (OS.Process.system (Config.rm - ^ " -rf " - ^ realLogDir oldUser))) + let + val ldir = realLogDir oldUser + in + if !logDeleted then + () + else + (ignore (OS.Process.system (down ())); + logDeleted := true); + ignore (OS.Process.system (Config.rm + ^ " -rf " + ^ realVhostFile)); + Slave.moveDirCreate {from = ldir, + to = Config.Apache.backupLogDirOf + (isVersion1 (Slave.hostname ()))} + end | Slave.Add => let val rld = realLogDir user @@ -298,7 +302,9 @@ val () = Slave.registerFileHandler (fn fs => if Posix.FileSys.access (rld, []) then () else - Slave.mkDirAll rld + Slave.moveDirCreate {from = Config.Apache.backupLogDirOf + (isVersion1 (Slave.hostname ())), + to = rld} end | _ => diff --git a/src/slave.sig b/src/slave.sig index 1a11e51..86c64fd 100644 --- a/src/slave.sig +++ b/src/slave.sig @@ -73,4 +73,7 @@ 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 a20f6db..7a507fa 100644 --- a/src/slave.sml +++ b/src/slave.sml @@ -209,4 +209,18 @@ 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)) + else + ()) + end -- 2.20.1