From 7db53a0b3693ddd01e6a36fc5bfb4ba56b4656eb Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sun, 10 Dec 2006 21:36:27 +0000 Subject: [PATCH] Apache log directory creation --- configDefault/apache.cfg | 2 +- configDefault/domtool.cfg | 1 + configDefault/domtool.cfs | 1 + src/plugins/apache.sml | 110 +++++++++++++++++++++++++++----------- src/slave.sig | 4 ++ src/slave.sml | 22 ++++++++ 6 files changed, 108 insertions(+), 32 deletions(-) diff --git a/configDefault/apache.cfg b/configDefault/apache.cfg index c5d6a22..088da4e 100644 --- a/configDefault/apache.cfg +++ b/configDefault/apache.cfg @@ -9,7 +9,7 @@ val webNodes = ["deleuze"] 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 diff --git a/configDefault/domtool.cfg b/configDefault/domtool.cfg index 908ee61..7024510 100644 --- a/configDefault/domtool.cfg +++ b/configDefault/domtool.cfg @@ -6,6 +6,7 @@ val cat = "/bin/cat" val cp = "/bin/cp" val diff = "/usr/bin/diff" val rm = "/bin/rm" +val echo = "/bin/echo" val defaultNs = "ns.hcoop.net" diff --git a/configDefault/domtool.cfs b/configDefault/domtool.cfs index 1dafb0c..472fff6 100644 --- a/configDefault/domtool.cfs +++ b/configDefault/domtool.cfs @@ -13,6 +13,7 @@ val cat : string val cp : string val diff : string val rm : string +val echo : string (* DNS SOA parameter defaults *) val defaultNs : string diff --git a/src/plugins/apache.sml b/src/plugins/apache.sml index ffd18b2..13fa497 100644 --- a/src/plugins/apache.sml +++ b/src/plugins/apache.sml @@ -173,38 +173,86 @@ val vhostsChanged = ref 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 => - 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 () => diff --git a/src/slave.sig b/src/slave.sig index 7d78217..b9abecd 100644 --- a/src/slave.sig +++ b/src/slave.sig @@ -56,4 +56,8 @@ signature SLAVE = sig 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 diff --git a/src/slave.sml b/src/slave.sml index fb336ae..b0148f1 100644 --- a/src/slave.sml +++ b/src/slave.sml @@ -154,4 +154,26 @@ fun enumerateTo p sep fname = 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 -- 2.20.1