forked from SteamWar/SteamWar
Merge pull request 'Fix CRIU subserver stop' (#485) from Hut512/SteamWar:main into main
Reviewed-on: SteamWar/SteamWar#485 Reviewed-by: YoyoNow <4+yoyonow@noreply.localhost>
This commit is contained in:
@@ -138,14 +138,16 @@ public class Subserver {
|
|||||||
writer.println(command);
|
writer.println(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ProcessHandle serverProcess() {
|
||||||
|
if (checkpoint) {
|
||||||
|
return process.children().findAny().orElseGet(process::toHandle);
|
||||||
|
}
|
||||||
|
return process.toHandle();
|
||||||
|
}
|
||||||
|
|
||||||
public void sleep() {
|
public void sleep() {
|
||||||
try {
|
try {
|
||||||
long pid = process.pid();
|
Runtime.getRuntime().exec(new String[]{"kill", "-SIGUSR1", Long.toString(serverProcess().pid())});
|
||||||
if (checkpoint) {
|
|
||||||
pid = process.children().findAny().map(ProcessHandle::pid).orElse(pid);
|
|
||||||
}
|
|
||||||
|
|
||||||
Runtime.getRuntime().exec(new String[]{"kill", "-SIGUSR1", Long.toString(pid)});
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.log(Level.SEVERE, "Failed to send SIGUSR1 to subserver.", e);
|
logger.log(Level.SEVERE, "Failed to send SIGUSR1 to subserver.", e);
|
||||||
}
|
}
|
||||||
@@ -162,7 +164,7 @@ public class Subserver {
|
|||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
try {
|
try {
|
||||||
process.destroy();
|
serverProcess().destroy();
|
||||||
if (!process.waitFor(1, TimeUnit.MINUTES)) {
|
if (!process.waitFor(1, TimeUnit.MINUTES)) {
|
||||||
forceStop();
|
forceStop();
|
||||||
} else if (thread.isAlive()) {
|
} else if (thread.isAlive()) {
|
||||||
@@ -177,6 +179,7 @@ public class Subserver {
|
|||||||
public void forceStop() {
|
public void forceStop() {
|
||||||
try {
|
try {
|
||||||
logger.log(Level.SEVERE, () -> serverName + " did not stop correctly, forcibly stopping!");
|
logger.log(Level.SEVERE, () -> serverName + " did not stop correctly, forcibly stopping!");
|
||||||
|
serverProcess().destroyForcibly();
|
||||||
process.destroyForcibly();
|
process.destroyForcibly();
|
||||||
|
|
||||||
if (thread.isAlive()) thread.join();
|
if (thread.isAlive()) thread.join();
|
||||||
|
|||||||
Reference in New Issue
Block a user