Added custom restart support

This commit is contained in:
Norbi Peti 2016-12-19 17:41:00 +01:00
parent 2887c16776
commit 6443d1d0b2
4 changed files with 65 additions and 8 deletions

20
.classpath Normal file
View 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>

View 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

View file

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View file

@ -7,6 +7,7 @@ import java.io.InputStreamReader;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Date; import java.util.Date;
import java.util.regex.Pattern;
import jline.console.ConsoleReader; import jline.console.ConsoleReader;
import jline.console.CursorBuffer; import jline.console.CursorBuffer;
@ -28,6 +29,8 @@ public class ServerRunner {
private static volatile ConsoleReader reader; private static volatile ConsoleReader reader;
private static volatile PrintWriter runnerout; private static volatile PrintWriter runnerout;
private static volatile boolean customrestartfailed = false;
public static void main(String[] args) throws IOException, InterruptedException { public static void main(String[] args) throws IOException, InterruptedException {
String minmem = "512M"; String minmem = "512M";
String maxmem = "1G"; String maxmem = "1G";
@ -95,6 +98,10 @@ public class ServerRunner {
ServerRunner.stop(); ServerRunner.stop();
writeToScreen("A server is already running!"); 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) { } else if (!stop) {
try { try {
serverinput.close(); serverinput.close();
@ -128,21 +135,35 @@ public class ServerRunner {
while (!stop) { while (!stop) {
try { try {
if (restartcounter >= 0) { if (restartcounter >= 0) {
if (restartcounter == RESTART_MESSAGE_COUNT) if (restartcounter == RESTART_MESSAGE_COUNT) {
if (firstrun) { if (firstrun) {
// writeToScreen("Sleeping for " + starttime); // writeToScreen("Sleeping for " + starttime);
Thread.sleep(starttime); Thread.sleep(starttime);
firstrun = false; firstrun = false;
} else } else
Thread.sleep(interval * 3600000); 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) if (restartcounter % 10 == 0)
sendMessage(serveroutput, "red", "-- Server restarting in " + restartcounter + " seconds!"); sendMessage(serveroutput, "red",
Thread.sleep(1000); // TODO: Change to bossbar? (plugin) "-- Server restarting in " + restartcounter + " seconds!");
Thread.sleep(1000);
} else { } 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..."); writeToScreen("Stopping server for restart...");
serveroutput.println("restart"); serveroutput.println("restart");
serveroutput.flush(); serveroutput.flush();
customrestartfailed = false;
}
Thread.sleep(5000); // Don't run needless cycles
} }
restartcounter--; restartcounter--;
} }