From 021959233f38d1bbcfe6fbcac4c64ab524a70eac Mon Sep 17 00:00:00 2001 From: Keuin Date: Fri, 8 May 2020 15:44:24 +0800 Subject: Added script-based auto reboot support (after restoring). --- .../kbackupfabric/util/ServerRestartUtil.java | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/main/java/com/keuin/kbackupfabric/util/ServerRestartUtil.java (limited to 'src/main/java/com/keuin/kbackupfabric/util') diff --git a/src/main/java/com/keuin/kbackupfabric/util/ServerRestartUtil.java b/src/main/java/com/keuin/kbackupfabric/util/ServerRestartUtil.java new file mode 100644 index 0000000..1642e5c --- /dev/null +++ b/src/main/java/com/keuin/kbackupfabric/util/ServerRestartUtil.java @@ -0,0 +1,58 @@ +package com.keuin.kbackupfabric.util; + +public class ServerRestartUtil { + + public static void forkAndRestart() { +// Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { +// @Override +// public void run() { +// // Here we restart the minecraft server +// StringBuilder cmd = new StringBuilder(); +// cmd.append(System.getProperty("java.home")).append(File.separator).append("bin").append(File.separator).append("java "); +// for (String jvmArg : ManagementFactory.getRuntimeMXBean().getInputArguments()) { +// cmd.append(jvmArg + " "); +// } +// cmd.append("-cp ").append(ManagementFactory.getRuntimeMXBean().getClassPath()).append(" "); +// cmd.append(MinecraftServer.class.getName()).append(" "); +// for (String arg : args) { +// cmd.append(arg).append(" "); +// } +// Runtime.getRuntime().exec(cmd.toString()); +// System.exit(0); +// } +// })); + } + + private static void startRestartThread() { +// (new Thread(() -> { +// +// +// // kill threads +// Set threads = Thread.getAllStackTraces().keySet(); +// Thread currentThread = Thread.currentThread(); +// for (Thread t : threads) { +// if(t != currentThread && t.isAlive()) { +// t.setUncaughtExceptionHandler((t1, e) -> { +// // set empty handler +// }); +// //t.interrupt(); +// try { +// t.setDaemon(true); +// } catch (Exception ignored) { +// } +// +// t.stop(); +// } +// } +// +// try { +// Thread.sleep(5000); +// } catch (InterruptedException ignored) { +// } +// +// // restart Minecraft server +// String[] args = new String[]{}; +// MinecraftServer.main(args); +// })).start(); + } +} -- cgit v1.2.3