-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create proto file containing server metadata on server startup
This is a combination of all of the other server files (except commandline). Meant to be used with exec-server to determine when the server is online and ready. It might also be useful to remove the individual info files (command_port, request_cookie, response_cookie) in favor of this one. RELNOTES: None PiperOrigin-RevId: 264650984
- Loading branch information
1 parent
447e0f1
commit b7f5605
Showing
2 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
import com.google.devtools.build.lib.server.CommandProtos.PingResponse; | ||
import com.google.devtools.build.lib.server.CommandProtos.RunRequest; | ||
import com.google.devtools.build.lib.server.CommandProtos.RunResponse; | ||
import com.google.devtools.build.lib.server.CommandProtos.ServerInfo; | ||
import com.google.devtools.build.lib.server.CommandProtos.StartupOption; | ||
import com.google.devtools.build.lib.util.ExitCode; | ||
import com.google.devtools.build.lib.util.Pair; | ||
|
@@ -314,6 +315,7 @@ public void run() { | |
private static final String PORT_FILE = "command_port"; | ||
private static final String REQUEST_COOKIE_FILE = "request_cookie"; | ||
private static final String RESPONSE_COOKIE_FILE = "response_cookie"; | ||
private static final String SERVER_INFO_FILE = "server_info.rawproto"; | ||
|
||
private static final AtomicBoolean runShutdownHooks = new AtomicBoolean(true); | ||
|
||
|
@@ -445,10 +447,7 @@ public void serve() throws IOException { | |
} | ||
serving = true; | ||
|
||
writeServerFile( | ||
PORT_FILE, InetAddresses.toUriString(address.getAddress()) + ":" + server.getPort()); | ||
writeServerFile(REQUEST_COOKIE_FILE, requestCookie); | ||
writeServerFile(RESPONSE_COOKIE_FILE, responseCookie); | ||
writeServerStatusFiles(address); | ||
|
||
try { | ||
server.awaitTermination(); | ||
|
@@ -458,6 +457,30 @@ public void serve() throws IOException { | |
} | ||
} | ||
|
||
private void writeServerStatusFiles(InetSocketAddress address) throws IOException { | ||
writeServerFile( | ||
PORT_FILE, InetAddresses.toUriString(address.getAddress()) + ":" + server.getPort()); | ||
writeServerFile(REQUEST_COOKIE_FILE, requestCookie); | ||
writeServerFile(RESPONSE_COOKIE_FILE, responseCookie); | ||
|
||
ServerInfo info = | ||
ServerInfo.newBuilder() | ||
.setPid(Integer.parseInt(pidInFile)) | ||
.setAddress(address.getAddress() + ":" + server.getPort()) | ||
.setRequestCookie(requestCookie) | ||
.setResponseCookie(responseCookie) | ||
.build(); | ||
|
||
// Write then mv so the user never sees incomplete contents. | ||
Path serverInfoTmpFile = serverDirectory.getChild(SERVER_INFO_FILE + ".tmp"); | ||
try (OutputStream out = serverInfoTmpFile.getOutputStream()) { | ||
info.writeTo(out); | ||
} | ||
Path serverInfoFile = serverDirectory.getChild(SERVER_INFO_FILE); | ||
serverInfoTmpFile.renameTo(serverInfoFile); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
meteorcloudy
Member
|
||
deleteAtExit(serverInfoFile); | ||
} | ||
|
||
private void writeServerFile(String name, String contents) throws IOException { | ||
Path file = serverDirectory.getChild(name); | ||
FileSystemUtils.writeContentAsLatin1(file, contents); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We probably should close the output stream before we rename the file otherwise it will fail on Windows. Because Windows doesn't allow deleting file while it's still open.