Added custom restart support
This commit is contained in:
parent
2887c16776
commit
6443d1d0b2
4 changed files with 65 additions and 8 deletions
20
.classpath
Normal file
20
.classpath
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
12
.settings/org.eclipse.jdt.core.prefs
Normal file
12
.settings/org.eclipse.jdt.core.prefs
Normal file
|
@ -0,0 +1,12 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
4
.settings/org.eclipse.m2e.core.prefs
Normal file
4
.settings/org.eclipse.m2e.core.prefs
Normal file
|
@ -0,0 +1,4 @@
|
|||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
|
@ -7,6 +7,7 @@ import java.io.InputStreamReader;
|
|||
import java.io.PrintWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import jline.console.ConsoleReader;
|
||||
import jline.console.CursorBuffer;
|
||||
|
@ -28,6 +29,8 @@ public class ServerRunner {
|
|||
private static volatile ConsoleReader reader;
|
||||
private static volatile PrintWriter runnerout;
|
||||
|
||||
private static volatile boolean customrestartfailed = false;
|
||||
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
String minmem = "512M";
|
||||
String maxmem = "1G";
|
||||
|
@ -95,6 +98,10 @@ public class ServerRunner {
|
|||
ServerRunner.stop();
|
||||
writeToScreen("A server is already running!");
|
||||
}
|
||||
if (Pattern.matches(
|
||||
"[\\d\\d:\\d\\d:\\d\\d INFO]: Unknown command. Type \"/help\" for help.\\s+", line))
|
||||
customrestartfailed = true;
|
||||
|
||||
} else if (!stop) {
|
||||
try {
|
||||
serverinput.close();
|
||||
|
@ -128,21 +135,35 @@ public class ServerRunner {
|
|||
while (!stop) {
|
||||
try {
|
||||
if (restartcounter >= 0) {
|
||||
if (restartcounter == RESTART_MESSAGE_COUNT)
|
||||
if (restartcounter == RESTART_MESSAGE_COUNT) {
|
||||
if (firstrun) {
|
||||
// writeToScreen("Sleeping for " + starttime);
|
||||
Thread.sleep(starttime);
|
||||
firstrun = false;
|
||||
} else
|
||||
Thread.sleep(interval * 3600000);
|
||||
else if (restartcounter > 0) {
|
||||
customrestartfailed = false;
|
||||
serveroutput.println("schrestart");
|
||||
serveroutput.flush();
|
||||
} else if (restartcounter > 0) {
|
||||
if (customrestartfailed) {
|
||||
if (restartcounter % 10 == 0)
|
||||
sendMessage(serveroutput, "red", "-- Server restarting in " + restartcounter + " seconds!");
|
||||
Thread.sleep(1000); // TODO: Change to bossbar? (plugin)
|
||||
sendMessage(serveroutput, "red",
|
||||
"-- Server restarting in " + restartcounter + " seconds!");
|
||||
Thread.sleep(1000);
|
||||
} else {
|
||||
restartcounter = RESTART_MESSAGE_COUNT;
|
||||
continue; // Don't decrement the counter so it will sleep the full time
|
||||
}
|
||||
} else {
|
||||
Thread.sleep(500);
|
||||
if (customrestartfailed) {
|
||||
writeToScreen("Stopping server for restart...");
|
||||
serveroutput.println("restart");
|
||||
serveroutput.flush();
|
||||
customrestartfailed = false;
|
||||
}
|
||||
Thread.sleep(5000); // Don't run needless cycles
|
||||
}
|
||||
restartcounter--;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue