Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Sep 6, 2024
1 parent 70081da commit aaaf2f8
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions main/server/src/mill/main/server/Server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class Server[T](

val serverId: String = java.lang.Long.toHexString(scala.util.Random.nextLong())
def serverLog0(s: String): Unit = {
if (running) {
if (running && checkServerIdFile()) {
os.write.append(serverDir / ServerFiles.serverLog, s"$s\n", createFolders = true)
}
}
Expand Down Expand Up @@ -92,29 +92,27 @@ abstract class Server[T](
def watchServerIdFile(): Unit = {
os.write.over(serverDir / ServerFiles.serverId, serverId)
val serverIdThread = new Thread(
() =>
while (
running && {
Thread.sleep(100)
Try(os.read(serverDir / ServerFiles.serverId)).toOption match {
case None =>
serverLog("serverId file missing")
exitServer()
false
case Some(s) =>
if (s == serverId) true
else {
serverLog(s"serverId file contents $s does not match serverId $serverId")
exitServer()
false
}
}
}
) (),
() => while (running && checkServerIdFile()) Thread.sleep(100),
"Server ID Checker Thread"
)
serverIdThread.start()
}
def checkServerIdFile() = {
Try(os.read(serverDir / ServerFiles.serverId)) match {
case scala.util.Failure(e) =>
serverLog(s"serverId file missing: $e")
exitServer()
false
case scala.util.Success(s) =>
if (s == serverId) true
else {
serverLog(s"serverId file contents $s does not match serverId $serverId")
exitServer()
false
}
}

}

def interruptWithTimeout[T](close: () => Unit, t: () => T): Option[T] = {
@volatile var interrupt = true
Expand Down

0 comments on commit aaaf2f8

Please sign in to comment.