geforkt von Mirrors/Paper
Allow the watchdog to try sanely stopping the server
Dieser Commit ist enthalten in:
Ursprung
afaba00192
Commit
f3bc708389
@ -5,7 +5,7 @@ Subject: [PATCH] Access items by EquipmentSlot
|
|||||||
|
|
||||||
|
|
||||||
diff --git a/src/main/java/org/bukkit/inventory/PlayerInventory.java b/src/main/java/org/bukkit/inventory/PlayerInventory.java
|
diff --git a/src/main/java/org/bukkit/inventory/PlayerInventory.java b/src/main/java/org/bukkit/inventory/PlayerInventory.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 557cc04d..799f1506 100644
|
||||||
--- a/src/main/java/org/bukkit/inventory/PlayerInventory.java
|
--- a/src/main/java/org/bukkit/inventory/PlayerInventory.java
|
||||||
+++ b/src/main/java/org/bukkit/inventory/PlayerInventory.java
|
+++ b/src/main/java/org/bukkit/inventory/PlayerInventory.java
|
||||||
@@ -0,0 +0,0 @@ public interface PlayerInventory extends Inventory {
|
@@ -0,0 +0,0 @@ public interface PlayerInventory extends Inventory {
|
||||||
|
@ -6,7 +6,7 @@ Subject: [PATCH] Add exception reporting event
|
|||||||
|
|
||||||
diff --git a/src/main/java/com/destroystokyo/paper/event/server/ServerExceptionEvent.java b/src/main/java/com/destroystokyo/paper/event/server/ServerExceptionEvent.java
|
diff --git a/src/main/java/com/destroystokyo/paper/event/server/ServerExceptionEvent.java b/src/main/java/com/destroystokyo/paper/event/server/ServerExceptionEvent.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
index 00000000..4109454a
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/com/destroystokyo/paper/event/server/ServerExceptionEvent.java
|
+++ b/src/main/java/com/destroystokyo/paper/event/server/ServerExceptionEvent.java
|
||||||
@@ -0,0 +0,0 @@
|
@@ -0,0 +0,0 @@
|
||||||
@ -49,7 +49,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/com/destroystokyo/paper/exception/ServerCommandException.java b/src/main/java/com/destroystokyo/paper/exception/ServerCommandException.java
|
diff --git a/src/main/java/com/destroystokyo/paper/exception/ServerCommandException.java b/src/main/java/com/destroystokyo/paper/exception/ServerCommandException.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
index 00000000..6fb39af0
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/com/destroystokyo/paper/exception/ServerCommandException.java
|
+++ b/src/main/java/com/destroystokyo/paper/exception/ServerCommandException.java
|
||||||
@@ -0,0 +0,0 @@
|
@@ -0,0 +0,0 @@
|
||||||
@ -119,7 +119,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/com/destroystokyo/paper/exception/ServerEventException.java b/src/main/java/com/destroystokyo/paper/exception/ServerEventException.java
|
diff --git a/src/main/java/com/destroystokyo/paper/exception/ServerEventException.java b/src/main/java/com/destroystokyo/paper/exception/ServerEventException.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
index 00000000..410b2413
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/com/destroystokyo/paper/exception/ServerEventException.java
|
+++ b/src/main/java/com/destroystokyo/paper/exception/ServerEventException.java
|
||||||
@@ -0,0 +0,0 @@
|
@@ -0,0 +0,0 @@
|
||||||
@ -177,7 +177,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/com/destroystokyo/paper/exception/ServerException.java b/src/main/java/com/destroystokyo/paper/exception/ServerException.java
|
diff --git a/src/main/java/com/destroystokyo/paper/exception/ServerException.java b/src/main/java/com/destroystokyo/paper/exception/ServerException.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
index 00000000..c06ea394
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/com/destroystokyo/paper/exception/ServerException.java
|
+++ b/src/main/java/com/destroystokyo/paper/exception/ServerException.java
|
||||||
@@ -0,0 +0,0 @@
|
@@ -0,0 +0,0 @@
|
||||||
@ -206,7 +206,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/com/destroystokyo/paper/exception/ServerInternalException.java b/src/main/java/com/destroystokyo/paper/exception/ServerInternalException.java
|
diff --git a/src/main/java/com/destroystokyo/paper/exception/ServerInternalException.java b/src/main/java/com/destroystokyo/paper/exception/ServerInternalException.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
index 00000000..e762ed0d
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/com/destroystokyo/paper/exception/ServerInternalException.java
|
+++ b/src/main/java/com/destroystokyo/paper/exception/ServerInternalException.java
|
||||||
@@ -0,0 +0,0 @@
|
@@ -0,0 +0,0 @@
|
||||||
@ -247,7 +247,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/com/destroystokyo/paper/exception/ServerPluginEnableDisableException.java b/src/main/java/com/destroystokyo/paper/exception/ServerPluginEnableDisableException.java
|
diff --git a/src/main/java/com/destroystokyo/paper/exception/ServerPluginEnableDisableException.java b/src/main/java/com/destroystokyo/paper/exception/ServerPluginEnableDisableException.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
index 00000000..f016ba3b
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/com/destroystokyo/paper/exception/ServerPluginEnableDisableException.java
|
+++ b/src/main/java/com/destroystokyo/paper/exception/ServerPluginEnableDisableException.java
|
||||||
@@ -0,0 +0,0 @@
|
@@ -0,0 +0,0 @@
|
||||||
@ -274,7 +274,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
\ No newline at end of file
|
\ No newline at end of file
|
||||||
diff --git a/src/main/java/com/destroystokyo/paper/exception/ServerPluginException.java b/src/main/java/com/destroystokyo/paper/exception/ServerPluginException.java
|
diff --git a/src/main/java/com/destroystokyo/paper/exception/ServerPluginException.java b/src/main/java/com/destroystokyo/paper/exception/ServerPluginException.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
index 00000000..6defac28
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/com/destroystokyo/paper/exception/ServerPluginException.java
|
+++ b/src/main/java/com/destroystokyo/paper/exception/ServerPluginException.java
|
||||||
@@ -0,0 +0,0 @@
|
@@ -0,0 +0,0 @@
|
||||||
@ -318,7 +318,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/com/destroystokyo/paper/exception/ServerPluginMessageException.java b/src/main/java/com/destroystokyo/paper/exception/ServerPluginMessageException.java
|
diff --git a/src/main/java/com/destroystokyo/paper/exception/ServerPluginMessageException.java b/src/main/java/com/destroystokyo/paper/exception/ServerPluginMessageException.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
index 00000000..89e13252
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/com/destroystokyo/paper/exception/ServerPluginMessageException.java
|
+++ b/src/main/java/com/destroystokyo/paper/exception/ServerPluginMessageException.java
|
||||||
@@ -0,0 +0,0 @@
|
@@ -0,0 +0,0 @@
|
||||||
@ -388,7 +388,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/com/destroystokyo/paper/exception/ServerSchedulerException.java b/src/main/java/com/destroystokyo/paper/exception/ServerSchedulerException.java
|
diff --git a/src/main/java/com/destroystokyo/paper/exception/ServerSchedulerException.java b/src/main/java/com/destroystokyo/paper/exception/ServerSchedulerException.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
index 00000000..2d0b2d4a
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/com/destroystokyo/paper/exception/ServerSchedulerException.java
|
+++ b/src/main/java/com/destroystokyo/paper/exception/ServerSchedulerException.java
|
||||||
@@ -0,0 +0,0 @@
|
@@ -0,0 +0,0 @@
|
||||||
@ -431,7 +431,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/com/destroystokyo/paper/exception/ServerTabCompleteException.java b/src/main/java/com/destroystokyo/paper/exception/ServerTabCompleteException.java
|
diff --git a/src/main/java/com/destroystokyo/paper/exception/ServerTabCompleteException.java b/src/main/java/com/destroystokyo/paper/exception/ServerTabCompleteException.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
index 00000000..5582999f
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/com/destroystokyo/paper/exception/ServerTabCompleteException.java
|
+++ b/src/main/java/com/destroystokyo/paper/exception/ServerTabCompleteException.java
|
||||||
@@ -0,0 +0,0 @@
|
@@ -0,0 +0,0 @@
|
||||||
@ -458,7 +458,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ }
|
+ }
|
||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java
|
diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 466757b9..08976cd4 100644
|
||||||
--- a/src/main/java/org/bukkit/command/SimpleCommandMap.java
|
--- a/src/main/java/org/bukkit/command/SimpleCommandMap.java
|
||||||
+++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java
|
+++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java
|
||||||
@@ -0,0 +0,0 @@ import java.util.List;
|
@@ -0,0 +0,0 @@ import java.util.List;
|
||||||
@ -494,7 +494,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
}
|
}
|
||||||
|
|
||||||
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index ffb68704..d1f7cdde 100644
|
||||||
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||||
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||||
@@ -0,0 +0,0 @@ import java.util.logging.Level;
|
@@ -0,0 +0,0 @@ import java.util.logging.Level;
|
||||||
|
@ -14,7 +14,7 @@ big slowdown in execution but throwing an exception at same time to raise awaren
|
|||||||
that it is happening so that plugin authors can fix their code to stop executing commands async.
|
that it is happening so that plugin authors can fix their code to stop executing commands async.
|
||||||
|
|
||||||
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||||
index 27283efad..57879c76d 100644
|
index 0fe8525dc..d983ca5cd 100644
|
||||||
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||||
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||||
@@ -0,0 +0,0 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
|
@@ -0,0 +0,0 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
|
||||||
|
@ -15,13 +15,60 @@ restart command, and adds separate handling for async calls, such as those from
|
|||||||
the watchdog thread.
|
the watchdog thread.
|
||||||
|
|
||||||
When calling from the watchdog thread, we cannot assume the main thread is in a
|
When calling from the watchdog thread, we cannot assume the main thread is in a
|
||||||
tickable state; it may be completely deadlocked. Therefore, we kill that thread
|
tickable state; it may be completely deadlocked. In order to handle this, we mark
|
||||||
right then and there.
|
the server as stopping, in order to account for situations where the server should
|
||||||
|
complete a tick reasonbly soon, i.e. 99% of cases.
|
||||||
|
|
||||||
|
Should the server not enter a state where it is stopping within 10 seconds, We
|
||||||
|
will assume that the server has in fact deadlocked and will proceed to force
|
||||||
|
kill the server.
|
||||||
|
|
||||||
|
This modification does not force restart the server should we actually enter a
|
||||||
|
deadlocked state where the server is stopping, whereas this will in most cases
|
||||||
|
exit within a reasonable amount of time, to put a fixed limit on a process that
|
||||||
|
will have plugins and worlds saving to the disk has a high potential to result
|
||||||
|
in corruption/dataloss.
|
||||||
|
|
||||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||||
index 8df30e3d0..df3077c9d 100644
|
index 8df30e3d0..9fdd61c7c 100644
|
||||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||||
|
@@ -0,0 +0,0 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
|
||||||
|
public WorldServer[] worldServer;
|
||||||
|
private PlayerList v;
|
||||||
|
private boolean isRunning = true;
|
||||||
|
+ private boolean isRestarting = false; // Paper - flag to signify we're attempting to restart
|
||||||
|
private boolean isStopped;
|
||||||
|
private int ticks;
|
||||||
|
protected final Proxy e;
|
||||||
|
@@ -0,0 +0,0 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
|
||||||
|
if (this.v != null) {
|
||||||
|
MinecraftServer.LOGGER.info("Saving players");
|
||||||
|
this.v.savePlayers();
|
||||||
|
- this.v.u();
|
||||||
|
+ this.v.u(isRestarting);
|
||||||
|
try { Thread.sleep(100); } catch (InterruptedException ex) {} // CraftBukkit - SPIGOT-625 - give server at least a chance to send packets
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +0,0 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
|
||||||
|
return this.isRunning;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ // Paper start - allow passing of the intent to restart
|
||||||
|
public void safeShutdown() {
|
||||||
|
+ safeShutdown(false);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public void safeShutdown(boolean isRestarting) {
|
||||||
|
this.isRunning = false;
|
||||||
|
+ this.isRestarting = isRestarting;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ // Paper end
|
||||||
|
+
|
||||||
|
// Paper start - Further improve server tick loop
|
||||||
|
private static final int TPS = 20;
|
||||||
|
private static final long SEC_IN_NANO = 1000000000;
|
||||||
@@ -0,0 +0,0 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
|
@@ -0,0 +0,0 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
|
||||||
return this.ab;
|
return this.ab;
|
||||||
}
|
}
|
||||||
@ -30,13 +77,58 @@ index 8df30e3d0..df3077c9d 100644
|
|||||||
public Thread aI() {
|
public Thread aI() {
|
||||||
return this.serverThread;
|
return this.serverThread;
|
||||||
}
|
}
|
||||||
|
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
|
||||||
|
index 034bdb7cf..34236c622 100644
|
||||||
|
--- a/src/main/java/net/minecraft/server/PlayerList.java
|
||||||
|
+++ b/src/main/java/net/minecraft/server/PlayerList.java
|
||||||
|
@@ -0,0 +0,0 @@ public abstract class PlayerList {
|
||||||
|
entityplayer.playerInteractManager.b(world.getWorldData().getGameType());
|
||||||
|
}
|
||||||
|
|
||||||
|
+ // Paper start - Extract method to allow for restarting flag
|
||||||
|
public void u() {
|
||||||
|
+ u(false);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public void u(boolean isRestarting) {
|
||||||
|
// CraftBukkit start - disconnect safely
|
||||||
|
for (EntityPlayer player : this.players) {
|
||||||
|
- player.playerConnection.disconnect(this.server.server.getShutdownMessage()); // CraftBukkit - add custom shutdown message
|
||||||
|
+ player.playerConnection.disconnect(!isRestarting ? this.server.server.getShutdownMessage() : org.spigotmc.SpigotConfig.restartMessage); // CraftBukkit - add custom shutdown message // Paper - add isRestarting flag
|
||||||
|
}
|
||||||
|
// CraftBukkit end
|
||||||
|
// Paper start - Remove collideRule team if it exists
|
||||||
|
@@ -0,0 +0,0 @@ public abstract class PlayerList {
|
||||||
|
}
|
||||||
|
// Paper end
|
||||||
|
}
|
||||||
|
+ // Paper end
|
||||||
|
|
||||||
|
// CraftBukkit start
|
||||||
|
public void sendMessage(IChatBaseComponent[] iChatBaseComponents) {
|
||||||
diff --git a/src/main/java/org/spigotmc/RestartCommand.java b/src/main/java/org/spigotmc/RestartCommand.java
|
diff --git a/src/main/java/org/spigotmc/RestartCommand.java b/src/main/java/org/spigotmc/RestartCommand.java
|
||||||
index 49768734d..35c828805 100644
|
index 49768734d..e1bc3e64e 100644
|
||||||
--- a/src/main/java/org/spigotmc/RestartCommand.java
|
--- a/src/main/java/org/spigotmc/RestartCommand.java
|
||||||
+++ b/src/main/java/org/spigotmc/RestartCommand.java
|
+++ b/src/main/java/org/spigotmc/RestartCommand.java
|
||||||
@@ -0,0 +0,0 @@ public class RestartCommand extends Command
|
@@ -0,0 +0,0 @@ public class RestartCommand extends Command
|
||||||
// Disable Watchdog
|
AsyncCatcher.enabled = false; // Disable async catcher incase it interferes with us
|
||||||
WatchdogThread.doStop();
|
try
|
||||||
|
{
|
||||||
|
- if ( script.isFile() )
|
||||||
|
- {
|
||||||
|
- System.out.println( "Attempting to restart with " + SpigotConfig.restartScript );
|
||||||
|
+ // Paper - extract method and cleanup
|
||||||
|
+ boolean isRestarting = addShutdownHook(script);
|
||||||
|
+ if (isRestarting) {
|
||||||
|
+ System.out.println("Attempting to restart with " + SpigotConfig.restartScript);
|
||||||
|
+ } else {
|
||||||
|
+ System.out.println( "Startup script '" + SpigotConfig.restartScript + "' does not exist! Stopping server." );
|
||||||
|
+ }
|
||||||
|
|
||||||
|
- // Disable Watchdog
|
||||||
|
- WatchdogThread.doStop();
|
||||||
|
+ // Stop the watchdog
|
||||||
|
+ WatchdogThread.doStop();
|
||||||
|
|
||||||
- // Kick all players
|
- // Kick all players
|
||||||
- for ( EntityPlayer p : (List< EntityPlayer>) MinecraftServer.getServer().getPlayerList().players )
|
- for ( EntityPlayer p : (List< EntityPlayer>) MinecraftServer.getServer().getPlayerList().players )
|
||||||
@ -60,7 +152,13 @@ index 49768734d..35c828805 100644
|
|||||||
- } catch ( InterruptedException ex )
|
- } catch ( InterruptedException ex )
|
||||||
- {
|
- {
|
||||||
- }
|
- }
|
||||||
-
|
+ shutdownServer(isRestarting);
|
||||||
|
+ } catch ( Exception ex )
|
||||||
|
+ {
|
||||||
|
+ ex.printStackTrace();
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
|
||||||
- // Actually shutdown
|
- // Actually shutdown
|
||||||
- try
|
- try
|
||||||
- {
|
- {
|
||||||
@ -68,17 +166,8 @@ index 49768734d..35c828805 100644
|
|||||||
- } catch ( Throwable t )
|
- } catch ( Throwable t )
|
||||||
- {
|
- {
|
||||||
- }
|
- }
|
||||||
+ shutdownServer(); // Paper - Moved to function that will handle sync and async
|
|
||||||
|
|
||||||
// This will be done AFTER the server has completely halted
|
|
||||||
Thread shutdownHook = new Thread()
|
|
||||||
@@ -0,0 +0,0 @@ public class RestartCommand extends Command
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+
|
|
||||||
+ // Paper start - sync copied from above with minor changes, async added
|
+ // Paper start - sync copied from above with minor changes, async added
|
||||||
+ private static void shutdownServer()
|
+ private static void shutdownServer(boolean isRestarting)
|
||||||
+ {
|
+ {
|
||||||
+ if (MinecraftServer.getServer().isMainThread())
|
+ if (MinecraftServer.getServer().isMainThread())
|
||||||
+ {
|
+ {
|
||||||
@ -94,20 +183,75 @@ index 49768734d..35c828805 100644
|
|||||||
+ } catch ( InterruptedException ex )
|
+ } catch ( InterruptedException ex )
|
||||||
+ {
|
+ {
|
||||||
+ }
|
+ }
|
||||||
+
|
|
||||||
|
- // This will be done AFTER the server has completely halted
|
||||||
|
- Thread shutdownHook = new Thread()
|
||||||
|
- {
|
||||||
|
- @Override
|
||||||
|
- public void run()
|
||||||
|
- {
|
||||||
|
- try
|
||||||
|
- {
|
||||||
|
- String os = System.getProperty( "os.name" ).toLowerCase(java.util.Locale.ENGLISH);
|
||||||
|
- if ( os.contains( "win" ) )
|
||||||
|
- {
|
||||||
|
- Runtime.getRuntime().exec( "cmd /c start " + script.getPath() );
|
||||||
|
- } else
|
||||||
|
- {
|
||||||
|
- Runtime.getRuntime().exec( new String[]
|
||||||
|
- {
|
||||||
|
- "sh", script.getPath()
|
||||||
|
- } );
|
||||||
|
- }
|
||||||
|
- } catch ( Exception e )
|
||||||
|
- {
|
||||||
|
- e.printStackTrace();
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- };
|
||||||
+ closeSocket();
|
+ closeSocket();
|
||||||
+
|
|
||||||
|
- shutdownHook.setDaemon( true );
|
||||||
|
- Runtime.getRuntime().addShutdownHook( shutdownHook );
|
||||||
|
- } else
|
||||||
+ // Actually shutdown
|
+ // Actually shutdown
|
||||||
+ try
|
+ try
|
||||||
+ {
|
{
|
||||||
|
- System.out.println( "Startup script '" + SpigotConfig.restartScript + "' does not exist! Stopping server." );
|
||||||
+ MinecraftServer.getServer().stop();
|
+ MinecraftServer.getServer().stop();
|
||||||
+ } catch ( Throwable t )
|
+ } catch ( Throwable t )
|
||||||
+ {
|
+ {
|
||||||
+ }
|
+ }
|
||||||
+ } else
|
+ } else
|
||||||
+ {
|
+ {
|
||||||
|
+ // Mark the server to shutdown at the end of the tick
|
||||||
|
+ MinecraftServer.getServer().safeShutdown(isRestarting);
|
||||||
|
|
||||||
|
- // Actually shutdown
|
||||||
|
- try
|
||||||
|
- {
|
||||||
|
- MinecraftServer.getServer().stop();
|
||||||
|
- } catch ( Throwable t )
|
||||||
|
- {
|
||||||
|
- }
|
||||||
|
+
|
||||||
|
+ // wait 10 seconds to see if we're actually going to try shutdown
|
||||||
|
+ try
|
||||||
|
+ {
|
||||||
|
+ Thread.sleep(10000);
|
||||||
|
+ }
|
||||||
|
+ catch (InterruptedException ignored)
|
||||||
|
+ {
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+ // Check if we've actually hit a state where the server is going to safely shutdown
|
||||||
|
+ // if we have, let the server stop as usual
|
||||||
|
+ if (MinecraftServer.getServer().isStopped()) return;
|
||||||
|
+
|
||||||
|
+ // If the server hasn't stopped by now, assume worse case and kill
|
||||||
+ closeSocket();
|
+ closeSocket();
|
||||||
+ MinecraftServer.getServer().getServerThread().stop();
|
System.exit( 0 );
|
||||||
|
- } catch ( Exception ex )
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
@ -118,12 +262,44 @@ index 49768734d..35c828805 100644
|
|||||||
+
|
+
|
||||||
+ // Give time for it to kick in
|
+ // Give time for it to kick in
|
||||||
+ try
|
+ try
|
||||||
+ {
|
{
|
||||||
|
- ex.printStackTrace();
|
||||||
+ Thread.sleep( 100 );
|
+ Thread.sleep( 100 );
|
||||||
+ } catch ( InterruptedException ex )
|
+ } catch ( InterruptedException ex )
|
||||||
+ {
|
+ {
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+ // Paper end
|
+ // Paper end
|
||||||
|
+
|
||||||
|
+ // Paper - copied from above and modified to return if the hook registered
|
||||||
|
+ private static boolean addShutdownHook(final File script) {
|
||||||
|
+
|
||||||
|
+ if (script.isFile()) {
|
||||||
|
+ Thread shutdownHook = new Thread() {
|
||||||
|
+ @Override
|
||||||
|
+ public void run() {
|
||||||
|
+ try {
|
||||||
|
+ String os = System.getProperty("os.name").toLowerCase(java.util.Locale.ENGLISH);
|
||||||
|
+ if (os.contains("win")) {
|
||||||
|
+ Runtime.getRuntime().exec("cmd /c start " + script.getPath());
|
||||||
|
+ } else {
|
||||||
|
+ Runtime.getRuntime().exec(new String[]
|
||||||
|
+ {
|
||||||
|
+ "sh", script.getPath()
|
||||||
|
+ });
|
||||||
|
+ }
|
||||||
|
+ } catch (Exception e) {
|
||||||
|
+ e.printStackTrace();
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ };
|
||||||
|
+
|
||||||
|
+ shutdownHook.setDaemon(true);
|
||||||
|
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
|
||||||
|
+ return true;
|
||||||
|
+ } else {
|
||||||
|
+ return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--
|
--
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren