Proper calculation of different log files for different hosts
[hcoop/domtool2.git] / src / plugins / apache.sml
index 511901c..1bb622b 100644 (file)
@@ -241,6 +241,13 @@ 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 logDir {user, node, vhostId} =
+    String.concat [Config.Apache.logDirOf (isVersion1 node) user,
+                  "/",
+                  node,
+                  "/",
+                  vhostId]
+
 val () = Slave.registerFileHandler (fn fs =>
                                       let
                                           val spl = OS.Path.splitDirFile (#file fs)
@@ -259,27 +266,15 @@ val () = Slave.registerFileHandler (fn fs =>
                                                       print ("Can't find user in " ^ #file fs ^ " or " ^ realVhostFile ^ "!  Taking no action.\n")
                                                   else
                                                       let
+                                                          val vhostId = if OS.Path.ext (#file spl) = SOME ".vhost_ssl" then
+                                                                            OS.Path.base (#file spl) ^ ".ssl"
+                                                                        else
+                                                                            OS.Path.base (#file spl)
+
                                                           fun realLogDir user =
-                                                              let
-                                                                  val realLogDir = Domain.homedirOf (valOf user)
-                                                                  val realLogDir = OS.Path.joinDirFile
-                                                                                       {dir = realLogDir,
-                                                                                        file = "apache"}
-                                                                  val realLogDir = OS.Path.joinDirFile
-                                                                                       {dir = realLogDir,
-                                                                                        file = "log"}
-                                                                  val realLogDir = OS.Path.joinDirFile
-                                                                                       {dir = realLogDir,
-                                                                                        file = Slave.hostname ()}
-                                                                  val {base, ...} = OS.Path.splitBaseExt (#file spl)
-
-                                                                  val realLogDir = OS.Path.concat (realLogDir, base)
-                                                              in
-                                                                  if String.isSuffix ".vhost_ssl" (#file spl) then
-                                                                      realLogDir ^ ".ssl"
-                                                                  else
-                                                                      realLogDir
-                                                              end
+                                                              logDir {user = valOf user,
+                                                                      node = Slave.hostname (),
+                                                                      vhostId = vhostId}
                                                       in
                                                           vhostsChanged := true;
                                                           case #action fs of
@@ -307,7 +302,7 @@ val () = Slave.registerFileHandler (fn fs =>
                                                                   if Posix.FileSys.access (rld, []) then
                                                                       ()
                                                                   else
-                                                                      OS.FileSys.mkDir rld
+                                                                      Slave.mkDirAll rld
                                                               end
                                                               
                                                             | _ =>
@@ -332,7 +327,7 @@ val () = Slave.registerFileHandler (fn fs =>
                                                                        if Posix.FileSys.access (rld, []) then
                                                                            ()
                                                                        else
-                                                                           OS.FileSys.mkDir rld
+                                                                           Slave.mkDirAll rld
                                                                    end
                                                                else
                                                                    ())
@@ -409,6 +404,8 @@ val () = Env.containerV_one "vhost"
                                       let
                                           val file = Domain.domainFile {node = node,
                                                                         name = confFile}
+
+                                          val ld = logDir {user = user, node = node, vhostId = vhostId}
                                       in
                                           TextIO.output (file, "# Owner: ");
                                           TextIO.output (file, user);
@@ -420,17 +417,9 @@ val () = Env.containerV_one "vhost"
                                                                  | NONE => "80");
                                           TextIO.output (file, ">\n");
                                           TextIO.output (file, "\tErrorLog ");
-                                          TextIO.output (file, Domain.homedirOf user);
-                                          TextIO.output (file, "/apache/log/");
-                                          TextIO.output (file, node);
-                                          TextIO.output (file, "/");
-                                          TextIO.output (file, vhostId);
+                                          TextIO.output (file, ld);
                                           TextIO.output (file, "/error.log\n\tCustomLog ");
-                                          TextIO.output (file, Domain.homedirOf user);
-                                          TextIO.output (file, "/apache/log/");
-                                          TextIO.output (file, node);
-                                          TextIO.output (file, "/");
-                                          TextIO.output (file, vhostId);
+                                          TextIO.output (file, ld);
                                           TextIO.output (file, "/access.log combined\n");
                                           TextIO.output (file, "\tServerName ");
                                           TextIO.output (file, fullHost);
@@ -454,8 +443,7 @@ val () = Env.containerV_one "vhost"
                                                TextIO.output (file, user))
                                           else
                                               ();
-                                          (Domain.homedirOf user ^ "/apache/log/"
-                                           ^ node ^ "/" ^ vhostId, file)
+                                          (ld, file)
                                       end)
                                   nodes;
                 write "\n\tDocumentRoot ";