in daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java [108:173]
public Server() {
// When spawning a new process, the child process is create within
// the same process group. This means that a few signals are sent
// to the whole group. This is the case for SIGINT (Ctrl-C) and
// SIGTSTP (Ctrl-Z) which are both sent to all the processed in the
// group when initiated from the controlling terminal.
// This is only a problem when the client creates the daemon, but
// without ignoring those signals, a client being interrupted will
// also interrupt and kill the daemon.
try {
SignalHelper.ignoreStopSignals();
} catch (Throwable t) {
LOGGER.warn("Unable to ignore INT and TSTP signals", t);
}
this.daemonId = Environment.MVND_ID.asString();
this.noDaemon = Environment.MVND_NO_DAEMON.asBoolean();
this.keepAliveMs = Environment.MVND_KEEP_ALIVE.asDuration().toMillis();
SocketFamily socketFamily = Environment.MVND_SOCKET_FAMILY
.asOptional()
.map(SocketFamily::valueOf)
.orElse(SocketFamily.inet);
try {
cli = (DaemonCli) getClass()
.getClassLoader()
.loadClass("org.apache.maven.cli.DaemonMavenCli")
.getDeclaredConstructor()
.newInstance();
registry = new DaemonRegistry(Environment.MVND_REGISTRY.asPath());
socket = socketFamily.openServerSocket();
executor = Executors.newScheduledThreadPool(1);
strategy = DaemonExpiration.master();
memoryStatus = new DaemonMemoryStatus(executor);
SecureRandom secureRandom = new SecureRandom();
byte[] token = new byte[DaemonInfo.TOKEN_SIZE];
secureRandom.nextBytes(token);
List<String> opts = new ArrayList<>();
Arrays.stream(Environment.values())
.filter(Environment::isDiscriminating)
.forEach(
envKey -> envKey.asOptional().ifPresent(val -> opts.add(envKey.getProperty() + "=" + val)));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(opts.stream()
.collect(Collectors.joining("\n ", "Initializing daemon with properties:\n ", "\n")));
}
long cur = System.currentTimeMillis();
info = new DaemonInfo(
daemonId,
Environment.MVND_JAVA_HOME.asString(),
Environment.MVND_HOME.asString(),
DaemonRegistry.getProcessId(),
SocketFamily.toString(socket.getLocalAddress()),
token,
Locale.getDefault().toLanguageTag(),
opts,
Busy,
cur,
cur);
registry.store(info);
} catch (Exception e) {
throw new RuntimeException("Could not initialize " + Server.class.getName(), e);
}
}