use of com.google.devtools.build.lib.remote.RemoteOptions in project bazel by bazelbuild.
the class RemoteWorker method main.
public static void main(String[] args) throws Exception {
OptionsParser parser = OptionsParser.newOptionsParser(RemoteOptions.class, RemoteWorkerOptions.class);
parser.parseAndExitUponError(args);
RemoteOptions remoteOptions = parser.getOptions(RemoteOptions.class);
RemoteWorkerOptions remoteWorkerOptions = parser.getOptions(RemoteWorkerOptions.class);
if (remoteWorkerOptions.workPath == null) {
printUsage(parser);
return;
}
System.out.println("*** Initializing in-memory cache server.");
ConcurrentMap<String, byte[]> cache = ConcurrentMapFactory.isRemoteCacheOptions(remoteOptions) ? ConcurrentMapFactory.create(remoteOptions) : new ConcurrentHashMap<String, byte[]>();
System.out.println("*** Starting grpc server on all locally bound IPs on port " + remoteWorkerOptions.listenPort + ".");
Path workPath = getFileSystem().getPath(remoteWorkerOptions.workPath);
FileSystemUtils.createDirectoryAndParents(workPath);
RemoteWorker worker = new RemoteWorker(workPath, remoteWorkerOptions, new ConcurrentMapActionCache(cache));
final Server server = ServerBuilder.forPort(remoteWorkerOptions.listenPort).addService(worker.getCasServer()).addService(worker.getExecutionServer()).addService(worker.getExecCacheServer()).build();
server.start();
final Path pidFile;
if (remoteWorkerOptions.pidFile != null) {
pidFile = getFileSystem().getPath(remoteWorkerOptions.pidFile);
PrintWriter writer = new PrintWriter(pidFile.getOutputStream());
writer.append(Integer.toString(ProcessUtils.getpid()));
writer.append("\n");
writer.close();
} else {
pidFile = null;
}
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.err.println("*** Shutting down grpc server.");
server.shutdown();
if (pidFile != null) {
try {
pidFile.delete();
} catch (IOException e) {
System.err.println("Cannot remove pid file: " + pidFile.toString());
}
}
System.err.println("*** Server shut down.");
}
});
server.awaitTermination();
}
Aggregations