val libRoot = "/afs/hcoop.net/common/etc/domtool/lib"
val resultRoot = "/afs/hcoop.net/common/etc/domtool/nodes"
val tmpDir = "/tmp/domtool"
+val oldResultRoot = "/afs/hcoop.net/common/etc/domtool/nodes.old"
val cat = "/bin/cat"
val cp = "/bin/cp"
(* Root directory for a directory hierarchy corresponding to domain structure,
* where each node contains Domtool-generated result files for that domain. *)
+val oldResultRoot : string
+(* Save an old copy for differencing *)
+
val tmpDir : string
(* Filesystem location for creating temporary directories *)
val hasPriv : string -> bool
val rmdom : string list -> unit
+ val rmdom' : string -> string list -> unit
val homedirOf : string -> string
val homedir : unit -> string
handle OS.SysErr _ =>
ErrorMsg.error NONE ("Delete failed for " ^ dst);
(site,
- {action = Slave.Delete,
+ {action = Slave.Delete true,
domain = dom,
dir = dir,
file = dst}))
orelse (hasPriv "mail"
andalso List.exists (fn x => x = node) Config.mailNodes_admin))
-fun rmdom doms =
+fun rmdom' delete resultRoot doms =
let
fun doNode (node, _) =
let
- val dname = OS.Path.joinDirFile {dir = Config.resultRoot,
+ val dname = OS.Path.joinDirFile {dir = resultRoot,
file = node}
fun doDom (dom, actions) =
loop (visitDom (fname ^ "." ^ dom,
fnameFull,
actions))
- else
- loop ({action = Slave.Delete,
- domain = dom,
- dir = dname,
- file = fnameFull} :: actions)
+ else
+ (print ("Kill " ^ fnameFull ^ "\n");
+ loop ({action = Slave.Delete delete,
+ domain = dom,
+ dir = dname,
+ file = fnameFull} :: actions))
end
in
loop actions
before Posix.FileSys.closedir dir
end
- handle OS.SysErr _ =>
- (print ("Warning: System error deleting domain " ^ dom ^ " on " ^ node ^ ".\n");
+ handle OS.SysErr (s, _) =>
+ (print ("Warning: System error deleting domain " ^ dom ^ " on " ^ node ^ ": " ^ s ^ "\n");
actions)
in
visitDom (dom, dname, actions)
fun doDom dom =
let
val domPath = String.concatWith "/" (rev (String.fields (fn ch => ch = #".") dom))
- val dname = OS.Path.joinDirFile {dir = Config.resultRoot,
+ val dname = OS.Path.joinDirFile {dir = resultRoot,
file = node}
val dname = OS.Path.concat (dname, domPath)
in
- ignore (OS.Process.system (Config.rm ^ " -rf " ^ dname))
+ if delete then
+ ignore (OS.Process.system (Config.rm ^ " -rf " ^ dname))
+ else
+ ()
end
in
app doDom doms
app cleanupNode Config.nodeIps
end
+val rmdom = rmdom' true Config.resultRoot
+val rmdom' = rmdom' false
+
fun homedirOf uname =
Posix.SysDB.Passwd.home (Posix.SysDB.getpwnam uname)
OpenSSL.close bio
end
+structure SS = StringSet
+
+fun domainList dname =
+ let
+ val dir = Posix.FileSys.opendir dname
+
+ fun visitNode dset =
+ case Posix.FileSys.readdir dir of
+ NONE => dset
+ | SOME node =>
+ let
+ val path = OS.Path.joinDirFile {dir = dname,
+ file = node}
+
+ fun visitDomains (path, bfor, dset) =
+ let
+ val dir = Posix.FileSys.opendir path
+
+ fun loop dset =
+ case Posix.FileSys.readdir dir of
+ NONE => dset
+ | SOME dname =>
+ let
+ val path = OS.Path.joinDirFile {dir = path,
+ file = dname}
+ in
+ if Posix.FileSys.ST.isDir (Posix.FileSys.stat path) then
+ let
+ val bfor = dname :: bfor
+ in
+ loop (visitDomains (path, bfor,
+ SS.add (dset,
+ String.concatWith "." bfor)))
+ end
+ else
+ loop dset
+ end
+ in
+ loop dset
+ before Posix.FileSys.closedir dir
+ end
+ in
+ visitNode (visitDomains (path, [], dset))
+ end
+ in
+ visitNode SS.empty
+ before Posix.FileSys.closedir dir
+ end
+
fun regenerateEither tc checker context =
let
+ val domainsBefore = domainList Config.resultRoot
+
fun ifReal f =
if tc then
()
val b = basis ()
val () = Tycheck.disallowExterns ()
- val () = ifReal Domain.resetGlobal
+ val () = ifReal (fn () =>
+ (ignore (OS.Process.system ("rm -rf " ^ Config.oldResultRoot ^ "/*"));
+ ignore (OS.Process.system ("cp -r " ^ Config.resultRoot
+ ^ "/* " ^ Config.oldResultRoot ^ "/"));
+ Domain.resetGlobal ()))
val ok = ref true
ifReal (fn () => (app contactNode Config.nodeIps;
Env.pre ()));
app doUser (Acl.users ());
- ifReal Env.post;
+ ifReal (fn () =>
+ let
+ val domainsAfter = domainList Config.resultRoot
+ val domainsGone = SS.difference (domainsBefore, domainsAfter)
+ in
+ if SS.isEmpty domainsGone then
+ ()
+ else
+ (print "Domains to kill:";
+ SS.app (fn s => (print " "; print s)) domainsGone;
+ print "\n";
+
+ Domain.rmdom' Config.oldResultRoot (SS.listItems domainsGone));
+
+ Env.post ()
+ end);
!ok
end
open OpenSSL MsgTypes Slave
val a2i = fn Add => 0
- | Delete => 1
+ | Delete true => 1
| Modify => 2
+ | Delete false => 3
val i2a = fn 0 => Add
- | 1 => Delete
+ | 1 => Delete true
| 2 => Modify
+ | 3 => Delete false
| _ => raise OpenSSL.OpenSSL "Bad action number to deserialize"
fun sendAcl (bio, {user, class, value}) =
val oldUser = findVhostUser realVhostFile
in
if (oldUser = NONE andalso #action fs <> Slave.Add)
- orelse (user = NONE andalso #action fs <> Slave.Delete) then
+ orelse (user = NONE andalso not (Slave.isDelete (#action fs))) then
print ("Can't find user in " ^ #file fs ^ " or " ^ realVhostFile ^ "! Taking no action.\n")
else
let
in
vhostsChanged := true;
case #action fs of
- Slave.Delete =>
+ Slave.Delete _ =>
let
val ldir = realLogDir oldUser
in
fun dnsChanged () =
if #domain fs = !didDomain then
()
- else if #action fs = Slave.Delete then
+ else if Slave.isDelete (#action fs) then
let
val fname = OS.Path.joinBaseExt {base = #domain fs,
ext = SOME "zone"}
file = base}
in
case #action fs of
- Slave.Delete =>
+ Slave.Delete _ =>
(ignore (OS.Process.system (Config.rm
^ " -f "
^ Config.Webalizer.configDir
datatype file_action =
Add
- | Delete
+ | Delete of bool (* Set to true to really delete the file *)
| Modify
+ val isDelete : file_action -> bool
+
type file_status = {action : file_action,
domain : string,
dir : string,
datatype file_action =
Add
- | Delete
+ | Delete of bool
| Modify
+fun isDelete (Delete _) = true
+ | isDelete _ = false
+
type file_status = {action : file_action,
domain : string,
dir : string,
fun handleChanges fs = (!preHandler ();
app (fn recd as {action, file, ...} =>
(!fileHandler recd;
- if action = Delete andalso Posix.FileSys.access (file, []) then
- OS.FileSys.remove file
- else
- ())) fs;
+ case action of
+ Delete b =>
+ if b andalso Posix.FileSys.access (file, []) then
+ OS.FileSys.remove file
+ else
+ ()
+ | _ => ())) fs;
!postHandler ())
fun shell ss = OS.Process.isSuccess (OS.Process.system (String.concat ss))