Proper backing up of Apache logs
[clinton/domtool2.git] / src / plugins / apache.sml
index 1f0fe83..4e07e4e 100644 (file)
@@ -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