Apache log directory creation
authorAdam Chlipala <adamc@hcoop.net>
Sun, 10 Dec 2006 21:36:27 +0000 (21:36 +0000)
committerAdam Chlipala <adamc@hcoop.net>
Sun, 10 Dec 2006 21:36:27 +0000 (21:36 +0000)
configDefault/apache.cfg
configDefault/domtool.cfg
configDefault/domtool.cfs
src/plugins/apache.sml
src/slave.sig
src/slave.sml

index c5d6a22..088da4e 100644 (file)
@@ -9,7 +9,7 @@ val webNodes = ["deleuze"]
 val proxyTargets = ["http://hcoop.net/cgi-bin/mailman",
                    "http://hcoop.net/pipermail"]
 
 val proxyTargets = ["http://hcoop.net/cgi-bin/mailman",
                    "http://hcoop.net/pipermail"]
 
-val logDir = "/var/log/apache2"
+val logDir = "/var/domtool/apache2_logs"
 val logDir_real = "/var/log/apache2"
 
 end
 val logDir_real = "/var/log/apache2"
 
 end
index 908ee61..7024510 100644 (file)
@@ -6,6 +6,7 @@ val cat = "/bin/cat"
 val cp = "/bin/cp"
 val diff = "/usr/bin/diff"
 val rm = "/bin/rm"
 val cp = "/bin/cp"
 val diff = "/usr/bin/diff"
 val rm = "/bin/rm"
+val echo = "/bin/echo"
 
 val defaultNs = "ns.hcoop.net"
 
 
 val defaultNs = "ns.hcoop.net"
 
index 1dafb0c..472fff6 100644 (file)
@@ -13,6 +13,7 @@ val cat : string
 val cp : string
 val diff : string
 val rm : string
 val cp : string
 val diff : string
 val rm : string
+val echo : string
 
 (* DNS SOA parameter defaults *)
 val defaultNs : string
 
 (* DNS SOA parameter defaults *)
 val defaultNs : string
index ffd18b2..13fa497 100644 (file)
@@ -173,38 +173,86 @@ val vhostsChanged = ref false
 val () = Slave.registerPreHandler
             (fn () => vhostsChanged := false)
 
 val () = Slave.registerPreHandler
             (fn () => vhostsChanged := false)
 
+fun findVhostUser fname =
+    let
+       val inf = TextIO.openIn fname
+
+       fun loop () =
+           case TextIO.inputLine inf of
+               NONE => NONE
+             | SOME line =>
+               case String.tokens Char.isSpace line of
+                   ["SuexecUserGroup", user, _] => SOME user
+                 | _ => loop ()
+    in
+       loop ()
+       before TextIO.closeIn inf
+    end
+
 val () = Slave.registerFileHandler (fn fs =>
 val () = Slave.registerFileHandler (fn fs =>
-                                      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 =>
-                                                   (ignore (OS.Process.system (Config.rm
-                                                                               ^ " -rf "
-                                                                               ^ Config.Apache.confDir
-                                                                               ^ "/"
-                                                                               ^ #file spl));
-                                                    ignore (OS.Process.system (Config.rm
-                                                                               ^ " -rf "
-                                                                               ^ Config.Apache.logDir
-                                                                               ^ "/"
-                                                                               ^ #base (OS.Path.splitBaseExt 
-                                                                                            (#file spl)))))
-                                                           
-                                                 | _ =>
-                                                   ignore (OS.Process.system (Config.cp
-                                                                              ^ " "
-                                                                              ^ #file fs
-                                                                              ^ " "
-                                                                              ^ Config.Apache.confDir
-                                                                              ^ "/"
-                                                                              ^ #file spl)))
-                                          else
-                                              ()
-                                      end)
+                                      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
+                                                           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)
 
 val () = Slave.registerPostHandler
         (fn () =>
 
 val () = Slave.registerPostHandler
         (fn () =>
index 7d78217..b9abecd 100644 (file)
@@ -56,4 +56,8 @@ signature SLAVE = sig
 
     val hostname : unit -> string
     (* Get hostname of this machine *)
 
     val hostname : unit -> string
     (* Get hostname of this machine *)
+
+    val readList : string -> string list
+    val writeList : string * string list -> unit
+    (* Reading and writing lists of strings stored on separate lines in files *)
 end
 end
index fb336ae..b0148f1 100644 (file)
@@ -154,4 +154,26 @@ fun enumerateTo p sep fname =
        TextIO.closeOut outf
     end
 
        TextIO.closeOut outf
     end
 
+fun readList fname =
+    let
+       val inf = TextIO.openIn fname
+
+       fun loop acc =
+           case TextIO.inputLine inf of
+               NONE => rev acc
+             | SOME line => loop (String.substring (line, 0, size line - 1) :: acc)
+    in
+       loop []
+       before TextIO.closeIn inf
+    end
+
+fun writeList (fname, ls) =
+    let
+       val outf = TextIO.openOut fname
+    in
+       app (fn s => (TextIO.output (outf, s);
+                     TextIO.output1 (outf, #"\n"))) ls;
+       TextIO.closeOut outf
+    end
+
 end
 end