- 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 =>
- (if !logDeleted then
- ()
- else
- (ignore (OS.Process.system Config.Apache.down);
- logDeleted := true);
- ignore (OS.Process.system (Config.rm
- ^ " -rf "
- ^ realVhostFile));
- ignore (OS.Process.system (Config.rm
- ^ " -rf "
- ^ realLogDir)))
- | Slave.Add =>
- (ignore (OS.Process.system (Config.cp
- ^ " "
- ^ #file fs
- ^ " "
- ^ realVhostFile));
- if Posix.FileSys.access (realLogDir, []) then
- ()
- else
- OS.FileSys.mkDir realLogDir)
-
- | _ =>
- ignore (OS.Process.system (Config.cp
- ^ " "
- ^ #file fs
- ^ " "
- ^ realVhostFile))
- end
+ orelse String.isSuffix ".vhost_ssl" (#file spl) then let
+ val realVhostFile = OS.Path.joinDirFile
+ {dir = Config.Apache.confDir,
+ file = #file spl}
+
+ val user = findVhostUser (#file fs)
+ val oldUser = findVhostUser realVhostFile
+ in
+ if (oldUser = NONE andalso #action fs <> Slave.Add)
+ orelse (user = NONE andalso #action fs <> Slave.Delete) then
+ 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 =
+ logDir {user = valOf user,
+ node = Slave.hostname (),
+ vhostId = vhostId}
+ in
+ vhostsChanged := true;
+ case #action fs of
+ Slave.Delete =>
+ (if !logDeleted then
+ ()
+ else
+ (ignore (OS.Process.system (down ()));
+ logDeleted := true);
+ ignore (OS.Process.system (Config.rm
+ ^ " -rf "
+ ^ realVhostFile));
+ ignore (OS.Process.system (Config.rm
+ ^ " -rf "
+ ^ realLogDir oldUser)))
+ | Slave.Add =>
+ let
+ val rld = realLogDir user
+ in
+ ignore (OS.Process.system (Config.cp
+ ^ " "
+ ^ #file fs
+ ^ " "
+ ^ realVhostFile));
+ if Posix.FileSys.access (rld, []) then
+ ()
+ else
+ Slave.mkDirAll rld
+ end
+
+ | _ =>
+ (ignore (OS.Process.system (Config.cp
+ ^ " "
+ ^ #file fs
+ ^ " "
+ ^ realVhostFile));
+ if user <> oldUser then
+ let
+ val old = realLogDir oldUser
+ val rld = realLogDir user
+ in
+ if !logDeleted then
+ ()
+ else
+ (ignore (OS.Process.system (down ()));
+ logDeleted := true);
+ ignore (OS.Process.system (Config.rm
+ ^ " -rf "
+ ^ realLogDir oldUser));
+ if Posix.FileSys.access (rld, []) then
+ ()
+ else
+ Slave.mkDirAll rld
+ end
+ else
+ ())
+ end
+ end