quick-e2e: Add shutdown hook and process management to Main class

This commit is contained in:
Oliver
2025-03-16 19:51:08 +01:00
parent 06e18e7572
commit 18f343de22
3 changed files with 26 additions and 1 deletions

View File

@@ -49,6 +49,20 @@ public class Main {
StartServerService startServer = new StartServerService();
startServer.startServer(context);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (context.serverProcess().isAlive()) {
context.serverProcess().destroy();
}
}));
if (context.serverProcess() != null && context.serverProcess().isAlive()) {
try {
context.serverProcess().waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}

View File

@@ -6,10 +6,13 @@ public class Context {
private final Configuration configuration;
private String actualBuildNumber;
private Path serverEnvPath;
private Path serverJarPath;
private Path startScriptPath;
private Process serverProcess;
public Context(Configuration configuration) {
this.configuration = configuration;
this.actualBuildNumber = configuration.build();
@@ -54,4 +57,12 @@ public class Context {
public void setStartScriptPath(Path startScriptPath) {
this.startScriptPath = startScriptPath;
}
public Process serverProcess() {
return serverProcess;
}
public void setServerProcess(Process serverProcess) {
this.serverProcess = serverProcess;
}
}

View File

@@ -10,7 +10,7 @@ public class StartServerService {
try {
Process process = processBuilder.start();
process.waitFor();
context.setServerProcess(process);
} catch (Exception e) {
e.printStackTrace();
}