Skip to content

Commit

Permalink
7.5.17
Browse files Browse the repository at this point in the history
- backup config now has other defaults, that cause no or less warnings to be shown than before
- added more debug logging to Server.start() and Server.stop() functions and made them synchronized to avoid concurrency issues if both got executed at the same time
  • Loading branch information
Osiris-Team committed Apr 27, 2024
1 parent fb15316 commit 4727585
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<groupId>com.osiris.autoplug.client</groupId>
<artifactId>autoplug-client</artifactId>
<version>7.5.16</version>
<version>7.5.17</version>
<packaging>jar</packaging>

<name>AutoPlug-Client</name>
Expand Down
29 changes: 24 additions & 5 deletions src/main/java/com/osiris/autoplug/client/Server.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Osiris-Team.
* Copyright (c) 2021-2024 Osiris-Team.
* All rights reserved.
*
* This software is copyrighted work, licensed under the terms
Expand Down Expand Up @@ -100,7 +100,7 @@ public static File getServerExecutable() throws NotLoadedException, YamlReaderEx
return serverExe;
}

public static void start() {
public static synchronized void start() {
try {
try {
colorServerLog = new LoggerConfig().color_server_log.asBoolean();
Expand All @@ -122,6 +122,8 @@ public static void start() {

AL.info("Starting server: " + serverExe.getName());
createProcess();
AL.debug(Server.class, "process: " + process);
AL.debug(Server.class, "ASYNC_SERVER_IN: " + ASYNC_SERVER_IN);
} catch (Exception e) {
AL.warn("Failed to start server: " + e.getMessage(), e);
}
Expand All @@ -141,9 +143,11 @@ public static void restart() {
/**
* Blocks until the server was stopped.
*/
public static void stop() throws IOException, InterruptedException, YamlWriterException, NotLoadedException, IllegalKeyException, DuplicateKeyException, YamlReaderException, IllegalListException {
public static synchronized void stop() throws IOException, InterruptedException, YamlWriterException, NotLoadedException, IllegalKeyException, DuplicateKeyException, YamlReaderException, IllegalListException {

AL.info("Stopping server...");
AL.debug(Server.class, "process: " + process);
AL.debug(Server.class, "ASYNC_SERVER_IN: " + ASYNC_SERVER_IN);

if (isRunning()) {
YamlSection stopCommand = new GeneralConfig().server_stop_command;
Expand All @@ -153,10 +157,25 @@ public static void stop() throws IOException, InterruptedException, YamlWriterEx
return;
}
for (SmartString v : values) {
AL.debug(Server.class, "Stopping server with command: \"" + v.asString() + "\"");
submitCommand(v.asString());
}
while (Server.isRunning())
int maxSeconds = 60 * 10;
int seconds = 0;
boolean inKillMode = false;
while (Server.isRunning()) {
Thread.sleep(1000);
seconds++;
if (seconds >= maxSeconds) {
if (inKillMode)
throw new IOException("Failed to stop (after 10 minutes) and kill (after 1 minute) server.");
inKillMode = true;
AL.warn("10 minutes have passed and the server is still running, killing it...");
kill();
seconds -= 60;
}
}

ASYNC_SERVER_IN = null;
} else {
AL.warn("Server not running!");
Expand All @@ -167,7 +186,7 @@ public static void stop() throws IOException, InterruptedException, YamlWriterEx
/**
* Blocks until server was killed.
*/
public static boolean kill() {
public static synchronized boolean kill() {
isKill.set(true);
AL.info("Killing server!");
try {
Expand Down

0 comments on commit 4727585

Please sign in to comment.