Made restart time independent of timezones
This commit is contained in:
parent
6443d1d0b2
commit
7b500f35b8
1 changed files with 10 additions and 7 deletions
|
@ -6,14 +6,15 @@ import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
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.Calendar;
|
||||||
|
import java.util.TimeZone;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import jline.console.ConsoleReader;
|
import jline.console.ConsoleReader;
|
||||||
import jline.console.CursorBuffer;
|
import jline.console.CursorBuffer;
|
||||||
|
|
||||||
public class ServerRunner {
|
public class ServerRunner {
|
||||||
private static final int RESTART_HOUR = 4;
|
private static final int RESTART_HOUR = 12;
|
||||||
|
|
||||||
private static final int RESTART_MESSAGE_COUNT = 60;
|
private static final int RESTART_MESSAGE_COUNT = 60;
|
||||||
|
|
||||||
|
@ -32,8 +33,8 @@ public class ServerRunner {
|
||||||
private static volatile boolean customrestartfailed = false;
|
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;
|
||||||
String maxmem = "1G";
|
String maxmem;
|
||||||
if (args.length == 3) {
|
if (args.length == 3) {
|
||||||
if ((!args[0].contains("G") && !args[0].contains("M"))
|
if ((!args[0].contains("G") && !args[0].contains("M"))
|
||||||
|| (!args[1].contains("G") && !args[0].contains("M"))) {
|
|| (!args[1].contains("G") && !args[0].contains("M"))) {
|
||||||
|
@ -131,6 +132,7 @@ public class ServerRunner {
|
||||||
ot.start();
|
ot.start();
|
||||||
Thread.currentThread().setName("RestarterThread");
|
Thread.currentThread().setName("RestarterThread");
|
||||||
long starttime = syncStart(RESTART_HOUR);
|
long starttime = syncStart(RESTART_HOUR);
|
||||||
|
System.out.println("Restart scheduled in " + starttime / 3600000f);
|
||||||
boolean firstrun = true;
|
boolean firstrun = true;
|
||||||
while (!stop) {
|
while (!stop) {
|
||||||
try {
|
try {
|
||||||
|
@ -215,12 +217,13 @@ public class ServerRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double hoursOf(Date parsedTime) {
|
private static double hoursOf(Calendar parsedTime) {
|
||||||
return parsedTime.getHours() + parsedTime.getMinutes() / 60. + parsedTime.getSeconds() / 3600.;
|
return parsedTime.get(Calendar.HOUR_OF_DAY) + parsedTime.get(Calendar.MINUTE) / 60.
|
||||||
|
+ parsedTime.get(Calendar.SECOND) / 3600.;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long syncStart(double startHour) { // Copied original code from SimpleBackup
|
private static long syncStart(double startHour) { // Copied original code from SimpleBackup
|
||||||
double now = hoursOf(new Date());
|
double now = hoursOf(Calendar.getInstance(TimeZone.getTimeZone("GMT")));
|
||||||
double diff = now - startHour;
|
double diff = now - startHour;
|
||||||
if (diff < 0) {
|
if (diff < 0) {
|
||||||
diff += 24;
|
diff += 24;
|
||||||
|
|
Loading…
Reference in a new issue