Changing Apache log and Webalizer stuff
authorAdam Chlipala <adamc@hcoop.net>
Sun, 10 Dec 2006 23:30:50 +0000 (23:30 +0000)
committerAdam Chlipala <adamc@hcoop.net>
Sun, 10 Dec 2006 23:30:50 +0000 (23:30 +0000)
Makefile
configDefault/apache.cfg
configDefault/apache.csg
src/plugins/apache.sig
src/plugins/apache.sml
src/plugins/webalizer.sml

index bd83eb1..036f5fa 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -36,22 +36,20 @@ openssl/openssl_sml.so: openssl/openssl_sml.o
 src/domtool.cm: Makefile src/prefix.cm src/sources
        cat src/prefix.cm src/sources >src/domtool.cm
 
+MAKE_MLB_BASE := cat src/prefix.mlb src/sources src/suffix.mlb \
+       | sed 's/^\(.*\).grm$$/\1.grm.sig\n\1.grm.sml/' \
+       | sed 's/^\(.*\).lex$$/\1.lex.sml/'
+
 src/domtool-server.mlb: Makefile src/prefix.mlb src/sources src/suffix.mlb
-       cat src/prefix.mlb src/sources src/suffix.mlb \
-               | sed 's/^\(.*\).grm$$/\1.grm.sig\n\1.grm.sml/' \
-               | sed 's/^\(.*\).lex$$/\1.lex.sml/' >src/domtool-server.mlb
+       $(MAKE_MLB_BASE) >src/domtool-server.mlb
        echo "main-server.sml" >>src/domtool-server.mlb
 
 src/domtool-client.mlb: Makefile src/prefix.mlb src/sources src/suffix.mlb
-       cat src/prefix.mlb src/sources src/suffix.mlb \
-               | sed 's/^\(.*\).grm$$/\1.grm.sig\n\1.grm.sml/' \
-               | sed 's/^\(.*\).lex$$/\1.lex.sml/' >src/domtool-client.mlb
+       $(MAKE_MLB_BASE) >src/domtool-client.mlb
        echo "main-client.sml" >>src/domtool-client.mlb
 
 src/domtool-slave.mlb: Makefile src/prefix.mlb src/sources src/suffix.mlb
-       cat src/prefix.mlb src/sources src/suffix.mlb \
-               | sed 's/^\(.*\).grm$$/\1.grm.sig\n\1.grm.sml/' \
-               | sed 's/^\(.*\).lex$$/\1.lex.sml/' >src/domtool-slave.mlb
+       $(MAKE_MLB_BASE) >src/domtool-slave.mlb
        echo "main-slave.sml" >>src/domtool-slave.mlb
 
 openssl/smlnj/FFI/libssl.h.cm: openssl/openssl_sml.h
@@ -70,25 +68,19 @@ openssl/mlton/FFI/libssl.h.mlb: openssl/openssl_sml.h
 %.grm.sig %.grm.sml: %.grm
        mlyacc $<
 
-bin/domtool-server: openssl/mlton/FFI/libssl.h.mlb \
-               src/domtool-server.mlb src/domtool.lex.sml \
-               src/domtool.grm.sig src/domtool.grm.sml \
-               $(COMMON_DEPS) src/*.sig src/*.sml \
-               src/plugins/*.sig src/plugins/*.sml
+COMMON_MLTON_DEPS := openssl/mlton/FFI/libssl.h.mlb \
+       src/domtool.lex.sml \
+       src/domtool.grm.sig src/domtool.grm.sml \
+       $(COMMON_DEPS) src/*.sig src/*.sml \
+       src/plugins/*.sig src/plugins/*.sml
+
+bin/domtool-server: $(COMMON_MLTON_DEPS) src/domtool-server.mlb 
        mlton -output bin/domtool-server -link-opt -ldl src/domtool-server.mlb
 
-bin/domtool-client: openssl/mlton/FFI/libssl.h.mlb \
-               src/domtool-client.mlb src/domtool.lex.sml \
-               src/domtool.grm.sig src/domtool.grm.sml \
-               $(COMMON_DEPS) src/*.sig src/*.sml \
-               src/plugins/*.sig src/plugins/*.sml
+bin/domtool-client: $(COMMON_MLTON_DEPS) src/domtool-client.mlb
        mlton -output bin/domtool-client -link-opt -ldl src/domtool-client.mlb
 
-bin/domtool-slave: openssl/mlton/FFI/libssl.h.mlb \
-               src/domtool-slave.mlb src/domtool.lex.sml \
-               src/domtool.grm.sig src/domtool.grm.sml \
-               $(COMMON_DEPS) src/*.sig src/*.sml \
-               src/plugins/*.sig src/plugins/*.sml
+bin/domtool-slave: $(COMMON_MLTON_DEPS) src/domtool-slave.mlb
        mlton -output bin/domtool-slave -link-opt -ldl src/domtool-slave.mlb
 
 install:
index 088da4e..bd5bc11 100644 (file)
@@ -9,7 +9,4 @@ val webNodes = ["deleuze"]
 val proxyTargets = ["http://hcoop.net/cgi-bin/mailman",
                    "http://hcoop.net/pipermail"]
 
-val logDir = "/var/domtool/apache2_logs"
-val logDir_real = "/var/log/apache2"
-
 end
index 148523a..dcf989c 100644 (file)
@@ -3,7 +3,6 @@ signature APACHE_CONFIG = sig
     val reload : string
 
     val confDir : string
-    val logDir : string
 
     val webNodes : string list
 
index f4142fd..db9966c 100644 (file)
@@ -20,7 +20,7 @@
 
 signature APACHE = sig
 
-    val registerPre : ({nodes : string list, id : string, hostname : string} -> unit) -> unit
+    val registerPre : ({user : string, nodes : string list, id : string, hostname : string} -> unit) -> unit
     (* Register a callback for the beginning of a vhost block. *)
 
     val registerPost : (unit -> unit) -> unit
index 13fa497..78ea612 100644 (file)
@@ -190,69 +190,63 @@ fun findVhostUser fname =
     end
 
 val () = Slave.registerFileHandler (fn fs =>
-                                      case findVhostUser (#file fs) of
-                                          NONE => print ("Can't find user in " ^ #file fs ^ "!  Taking no action.\n")
-                                        | SOME user =>
-                                          let
-                                              val spl = OS.Path.splitDirFile (#file fs)
-                                          in
-                                              if String.isSuffix ".vhost" (#file spl)
-                                                 orelse String.isSuffix ".vhost_ssl" (#file spl) then
-                                                  (vhostsChanged := true;
-                                                   case #action fs of
-                                                       Slave.Delete =>
-                                                       let
-                                                           val {base, ...} = OS.Path.splitBaseExt (#file spl)
-
-                                                           val logname = OS.Path.joinDirFile
-                                                                             {dir = Config.Apache.logDir,
-                                                                              file = user}
-                                                       in
+                                      let
+                                          val spl = OS.Path.splitDirFile (#file fs)
+                                      in
+                                          if String.isSuffix ".vhost" (#file spl)
+                                             orelse String.isSuffix ".vhost_ssl" (#file spl) then
+                                              case findVhostUser (#file fs) of
+                                                  NONE => print ("Can't find user in " ^ #file fs ^ "!  Taking no action.\n")
+                                                | SOME user =>
+                                                  let
+                                                      val realVhostFile = OS.Path.joinDirFile
+                                                                              {dir = Config.Apache.confDir,
+                                                                               file = #file spl}
+
+                                                      val realLogDir = OS.Path.joinDirFile
+                                                                           {dir = Config.homeBase,
+                                                                            file = 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.joinDirFile
+                                                                           {dir = realLogDir,
+                                                                            file = base}
+                                                  in
+                                                      vhostsChanged := true;
+                                                      case #action fs of
+                                                          Slave.Delete =>
+                                                          (ignore (OS.Process.system (Config.rm
+                                                                                      ^ " -rf "
+                                                                                      ^ realVhostFile));
                                                            ignore (OS.Process.system (Config.rm
                                                                                       ^ " -rf "
-                                                                                      ^ Config.Apache.confDir
-                                                                                      ^ "/"
-                                                                                      ^ #file spl));
-                                                           Slave.writeList (logname,
-                                                                            List.filter (fn s => s <> base)
-                                                                                        (Slave.readList logname))
-                                                       end
-                                                       
-                                                     | Slave.Add =>
-                                                       let
-                                                           val _ = 
-                                                               OS.Process.system (Config.cp
-                                                                                  ^ " "
-                                                                                  ^ #file fs
-                                                                                  ^ " "
-                                                                                  ^ Config.Apache.confDir
-                                                                                  ^ "/"
-                                                                                  ^ #file spl)
-
-                                                           val {base, ...} = OS.Path.splitBaseExt (#file spl)
-
-                                                           val logname = OS.Path.joinDirFile
-                                                                             {dir = Config.Apache.logDir,
-                                                                              file = user}
-
-                                                           val outf = TextIO.openAppend logname
-                                                       in
-                                                           TextIO.output (outf, base);
-                                                           TextIO.output1 (outf, #"\n");
-                                                           TextIO.closeOut outf
-                                                       end
-        
-                                                     | _ =>
-                                                       ignore (OS.Process.system (Config.cp
-                                                                                  ^ " "
-                                                                                  ^ #file fs
-                                                                                  ^ " "
-                                                                                  ^ Config.Apache.confDir
-                                                                                  ^ "/"
-                                                                                  ^ #file spl)))
-                                              else
-                                                  ()
-                                          end)
+                                                                                      ^ realLogDir)))
+                                                        | Slave.Add =>
+                                                          (ignore (OS.Process.system (Config.cp
+                                                                                      ^ " "
+                                                                                      ^ #file fs
+                                                                                      ^ " "
+                                                                                      ^ realVhostFile));
+                                                           OS.FileSys.mkDir realLogDir)
+                                                          
+                                                        | _ =>
+                                                          ignore (OS.Process.system (Config.cp
+                                                                                     ^ " "
+                                                                                     ^ #file fs
+                                                                                     ^ " "
+                                                                                     ^ realVhostFile))
+                                                  end
+                                          else
+                                              ()
+                                      end)
 
 val () = Slave.registerPostHandler
         (fn () =>
@@ -262,14 +256,15 @@ val () = Slave.registerPostHandler
              else
                  ()))
 
-val vhostFiles : TextIO.outstream list ref = ref []
-fun write s = app (fn file => TextIO.output (file, s)) (!vhostFiles)
+val vhostFiles : (string * TextIO.outstream) list ref = ref []
+fun write' s = app (fn (node, file) => TextIO.output (file, s node)) (!vhostFiles)
+fun write s = app (fn (_, file) => TextIO.output (file, s)) (!vhostFiles)
 
 val rewriteEnabled = ref false
 val currentVhost = ref ""
 val currentVhostId = ref ""
 
-val pre = ref (fn _ : {nodes : string list, id : string, hostname : string} => ())
+val pre = ref (fn _ : {user : string, nodes : string list, id : string, hostname : string} => ())
 fun registerPre f =
     let
        val old = !pre
@@ -326,7 +321,25 @@ val () = Env.containerV_one "vhost"
                                                                else
                                                                    "80");
                                           TextIO.output (file, ">\n");
-                                          file
+                                          TextIO.output (file, "\tErrorLog ");
+                                          TextIO.output (file, Config.homeBase);
+                                          TextIO.output (file, "/");
+                                          TextIO.output (file, user);
+                                          TextIO.output (file, "/apache/log/");
+                                          TextIO.output (file, node);
+                                          TextIO.output (file, "/");
+                                          TextIO.output (file, vhostId);
+                                          TextIO.output (file, "/error.log\n\tCustomLog ");
+                                          TextIO.output (file, Config.homeBase);
+                                          TextIO.output (file, "/");
+                                          TextIO.output (file, user);
+                                          TextIO.output (file, "/apache/log/");
+                                          TextIO.output (file, node);
+                                          TextIO.output (file, "/");
+                                          TextIO.output (file, vhostId);
+                                          TextIO.output (file, "/access.log combined\n");
+                                          (Config.homeBase ^ "/" ^ user ^ "/apache/log/"
+                                           ^ node ^ "/" ^ vhostId, file)
                                       end)
                                   nodes;
                 write "\tServerName ";
@@ -339,20 +352,12 @@ val () = Env.containerV_one "vhost"
                 write docroot;
                 write "\n\tServerAdmin ";
                 write sadmin;
-                write "\n\tErrorLog ";
-                write Config.Apache.logDir;
-                write "/";
-                write vhostId;
-                write "/error.log\n\tCustomLog ";
-                write Config.Apache.logDir;
-                write "/";
-                write vhostId;
-                write "/access.log combined\n";
-                !pre {nodes = nodes, id = vhostId, hostname = fullHost}
+                write "\n";
+                !pre {user = user, nodes = nodes, id = vhostId, hostname = fullHost}
             end,
          fn () => (!post ();
                    write "</VirtualHost>\n";
-                   app TextIO.closeOut (!vhostFiles)))
+                   app (TextIO.closeOut o #2) (!vhostFiles)))
 
 val () = Env.container_one "location"
         ("prefix", Env.string)
@@ -446,9 +451,7 @@ val () = Env.action_one "rewriteLogLevel"
         (fn level =>
             (checkRewrite ();
              write "\tRewriteLog ";
-             write Config.Apache.logDir;
-             write "/";
-             write (!currentVhostId);
+             write' (fn x => x);
              write "/rewrite.log\n\tRewriteLogLevel ";
              write (Int.toString level);
              write "\n"))
index f88f2ff..313a582 100644 (file)
@@ -24,22 +24,31 @@ val files = ref ([] : TextIO.outstream list)
 val write = ref (fn _ : string => ())
 
 val () = Apache.registerPre
-        (fn {nodes, id, hostname} =>
+        (fn {user, nodes, id, hostname} =>
             let
-                val fds = map (fn node => Domain.domainFile {node = node,
-                                                             name = id ^ ".wbl"}) nodes
+                val fds = map (fn node =>
+                                  let
+                                      val fd = Domain.domainFile {node = node,
+                                                                  name = id ^ ".wbl"}
+                                  in
+                                      TextIO.output (fd, "LogFile\t");
+                                      TextIO.output (fd, Config.homeBase);
+                                      TextIO.output (fd, "/apache/log/");
+                                      TextIO.output (fd, node);
+                                      TextIO.output (fd, hostname);
+                                      TextIO.output (fd, "/access.log\nOutputDir\t");
+                                      TextIO.output (fd, Config.Webalizer.outputDir);
+                                      TextIO.output (fd, "/");
+                                      TextIO.output (fd, node);
+                                      TextIO.output (fd, "/");
+                                      TextIO.output (fd, id);
+                                      TextIO.output (fd, "\n");
+                                      fd
+                                  end) nodes
             in
                 files := fds;
                 write := (fn s => app (fn fd => TextIO.output (fd, s)) fds);
-                !write "LogFile\t";
-                !write Config.Apache.logDir;
-                !write "/";
-                !write hostname;
-                !write "/access.log\nOutputDir\t";
-                !write Config.Webalizer.outputDir;
-                !write "/";
-                !write id;
-                !write "\nHostname\t";
+                !write "Hostname\t";
                 !write hostname;
                 !write "\nHideSite\t";
                 !write hostname;