mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-30 14:33:56 +01:00
Re: Actually exit the JVM after stopping the server when /restart is ran
This commit is contained in:
parent
5e40806ee2
commit
c829f34e0c
@ -1,4 +1,4 @@
|
|||||||
From 7b1933c71d02d89958060b7f42de0f5c7c7adf68 Mon Sep 17 00:00:00 2001
|
From c4d55d1a8975ff584d14bf11ab108105ff349566 Mon Sep 17 00:00:00 2001
|
||||||
From: Zach Brown <zach.brown@destroystokyo.com>
|
From: Zach Brown <zach.brown@destroystokyo.com>
|
||||||
Date: Fri, 12 May 2017 23:34:11 -0500
|
Date: Fri, 12 May 2017 23:34:11 -0500
|
||||||
Subject: [PATCH] Properly handle async calls to restart the server
|
Subject: [PATCH] Properly handle async calls to restart the server
|
||||||
@ -30,7 +30,7 @@ will have plugins and worlds saving to the disk has a high potential to result
|
|||||||
in corruption/dataloss.
|
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 42769d164..6c5b40f32 100644
|
index eb5858189..d84f59da1 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
|
||||||
@@ -70,6 +70,7 @@ public abstract class MinecraftServer implements ICommandListener, Runnable, IAs
|
@@ -70,6 +70,7 @@ public abstract class MinecraftServer implements ICommandListener, Runnable, IAs
|
||||||
@ -78,7 +78,7 @@ index 42769d164..6c5b40f32 100644
|
|||||||
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
|
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
|
||||||
index 772670a03..34f113ee5 100644
|
index a988fc8b9..0c3287823 100644
|
||||||
--- a/src/main/java/net/minecraft/server/PlayerList.java
|
--- a/src/main/java/net/minecraft/server/PlayerList.java
|
||||||
+++ b/src/main/java/net/minecraft/server/PlayerList.java
|
+++ b/src/main/java/net/minecraft/server/PlayerList.java
|
||||||
@@ -1361,10 +1361,15 @@ public abstract class PlayerList {
|
@@ -1361,10 +1361,15 @@ public abstract class PlayerList {
|
||||||
@ -107,16 +107,14 @@ index 772670a03..34f113ee5 100644
|
|||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
public void sendMessage(IChatBaseComponent[] iChatBaseComponents) {
|
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..e1bc3e64e 100644
|
index 49768734d..d51636c8e 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
|
||||||
@@ -45,88 +45,119 @@ public class RestartCommand extends Command
|
@@ -45,88 +45,123 @@ public class RestartCommand extends Command
|
||||||
AsyncCatcher.enabled = false; // Disable async catcher incase it interferes with us
|
AsyncCatcher.enabled = false; // Disable async catcher incase it interferes with us
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
- if ( script.isFile() )
|
- if ( script.isFile() )
|
||||||
- {
|
|
||||||
- System.out.println( "Attempting to restart with " + SpigotConfig.restartScript );
|
|
||||||
+ // Paper - extract method and cleanup
|
+ // Paper - extract method and cleanup
|
||||||
+ boolean isRestarting = addShutdownHook(script);
|
+ boolean isRestarting = addShutdownHook(script);
|
||||||
+ if (isRestarting) {
|
+ if (isRestarting) {
|
||||||
@ -124,48 +122,17 @@ index 49768734d..e1bc3e64e 100644
|
|||||||
+ } else {
|
+ } else {
|
||||||
+ System.out.println( "Startup script '" + SpigotConfig.restartScript + "' does not exist! Stopping server." );
|
+ System.out.println( "Startup script '" + SpigotConfig.restartScript + "' does not exist! Stopping server." );
|
||||||
+ }
|
+ }
|
||||||
|
+
|
||||||
- // Disable Watchdog
|
|
||||||
- WatchdogThread.doStop();
|
|
||||||
+ // Stop the watchdog
|
+ // Stop the watchdog
|
||||||
+ WatchdogThread.doStop();
|
+ WatchdogThread.doStop();
|
||||||
|
+
|
||||||
- // Kick all players
|
|
||||||
- for ( EntityPlayer p : (List< EntityPlayer>) MinecraftServer.getServer().getPlayerList().players )
|
|
||||||
- {
|
|
||||||
- p.playerConnection.disconnect(SpigotConfig.restartMessage);
|
|
||||||
- }
|
|
||||||
- // Give the socket a chance to send the packets
|
|
||||||
- try
|
|
||||||
- {
|
|
||||||
- Thread.sleep( 100 );
|
|
||||||
- } catch ( InterruptedException ex )
|
|
||||||
- {
|
|
||||||
- }
|
|
||||||
- // Close the socket so we can rebind with the new process
|
|
||||||
- MinecraftServer.getServer().getServerConnection().b();
|
|
||||||
-
|
|
||||||
- // Give time for it to kick in
|
|
||||||
- try
|
|
||||||
- {
|
|
||||||
- Thread.sleep( 100 );
|
|
||||||
- } catch ( InterruptedException ex )
|
|
||||||
- {
|
|
||||||
- }
|
|
||||||
+ shutdownServer(isRestarting);
|
+ shutdownServer(isRestarting);
|
||||||
+ } catch ( Exception ex )
|
+ } catch ( Exception ex )
|
||||||
+ {
|
+ {
|
||||||
+ ex.printStackTrace();
|
+ ex.printStackTrace();
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
|
+
|
||||||
- // Actually shutdown
|
|
||||||
- try
|
|
||||||
- {
|
|
||||||
- MinecraftServer.getServer().stop();
|
|
||||||
- } catch ( Throwable t )
|
|
||||||
- {
|
|
||||||
- }
|
|
||||||
+ // 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(boolean isRestarting)
|
+ private static void shutdownServer(boolean isRestarting)
|
||||||
+ {
|
+ {
|
||||||
@ -181,9 +148,58 @@ index 49768734d..e1bc3e64e 100644
|
|||||||
+ {
|
+ {
|
||||||
+ Thread.sleep( 100 );
|
+ Thread.sleep( 100 );
|
||||||
+ } catch ( InterruptedException ex )
|
+ } catch ( InterruptedException ex )
|
||||||
|
{
|
||||||
|
- System.out.println( "Attempting to restart with " + SpigotConfig.restartScript );
|
||||||
|
+ }
|
||||||
|
|
||||||
|
- // Disable Watchdog
|
||||||
|
- WatchdogThread.doStop();
|
||||||
|
+ closeSocket();
|
||||||
|
|
||||||
|
- // Kick all players
|
||||||
|
- for ( EntityPlayer p : (List< EntityPlayer>) MinecraftServer.getServer().getPlayerList().players )
|
||||||
|
- {
|
||||||
|
- p.playerConnection.disconnect(SpigotConfig.restartMessage);
|
||||||
|
- }
|
||||||
|
- // Give the socket a chance to send the packets
|
||||||
|
- try
|
||||||
|
- {
|
||||||
|
- Thread.sleep( 100 );
|
||||||
|
- } catch ( InterruptedException ex )
|
||||||
|
- {
|
||||||
|
- }
|
||||||
|
- // Close the socket so we can rebind with the new process
|
||||||
|
- MinecraftServer.getServer().getServerConnection().b();
|
||||||
|
+ // Actually shutdown
|
||||||
|
+ try
|
||||||
|
+ {
|
||||||
|
+ MinecraftServer.getServer().stop();
|
||||||
|
+ } catch ( Throwable t )
|
||||||
+ {
|
+ {
|
||||||
+ }
|
+ }
|
||||||
|
|
||||||
|
- // Give time for it to kick in
|
||||||
|
- try
|
||||||
|
- {
|
||||||
|
- Thread.sleep( 100 );
|
||||||
|
- } catch ( InterruptedException ex )
|
||||||
|
- {
|
||||||
|
- }
|
||||||
|
+ // Actually stop the JVM
|
||||||
|
+ System.exit(0);
|
||||||
|
|
||||||
|
- // Actually shutdown
|
||||||
|
- try
|
||||||
|
- {
|
||||||
|
- MinecraftServer.getServer().stop();
|
||||||
|
- } catch ( Throwable t )
|
||||||
|
- {
|
||||||
|
- }
|
||||||
|
+ } else
|
||||||
|
+ {
|
||||||
|
+ // Mark the server to shutdown at the end of the tick
|
||||||
|
+ MinecraftServer.getServer().safeShutdown(isRestarting);
|
||||||
|
|
||||||
- // This will be done AFTER the server has completely halted
|
- // This will be done AFTER the server has completely halted
|
||||||
- Thread shutdownHook = new Thread()
|
- Thread shutdownHook = new Thread()
|
||||||
- {
|
- {
|
||||||
@ -209,24 +225,19 @@ index 49768734d..e1bc3e64e 100644
|
|||||||
- }
|
- }
|
||||||
- }
|
- }
|
||||||
- };
|
- };
|
||||||
+ closeSocket();
|
|
||||||
|
|
||||||
- shutdownHook.setDaemon( true );
|
- shutdownHook.setDaemon( true );
|
||||||
- Runtime.getRuntime().addShutdownHook( shutdownHook );
|
- Runtime.getRuntime().addShutdownHook( shutdownHook );
|
||||||
- } else
|
- } else
|
||||||
+ // Actually shutdown
|
+ // wait 10 seconds to see if we're actually going to try shutdown
|
||||||
+ try
|
+ try
|
||||||
|
+ {
|
||||||
|
+ Thread.sleep(10000);
|
||||||
|
+ }
|
||||||
|
+ catch (InterruptedException ignored)
|
||||||
{
|
{
|
||||||
- System.out.println( "Startup script '" + SpigotConfig.restartScript + "' does not exist! Stopping server." );
|
- System.out.println( "Startup script '" + SpigotConfig.restartScript + "' does not exist! Stopping server." );
|
||||||
+ MinecraftServer.getServer().stop();
|
-
|
||||||
+ } catch ( Throwable t )
|
|
||||||
+ {
|
|
||||||
+ }
|
|
||||||
+ } else
|
|
||||||
+ {
|
|
||||||
+ // Mark the server to shutdown at the end of the tick
|
|
||||||
+ MinecraftServer.getServer().safeShutdown(isRestarting);
|
|
||||||
|
|
||||||
- // Actually shutdown
|
- // Actually shutdown
|
||||||
- try
|
- try
|
||||||
- {
|
- {
|
||||||
@ -234,14 +245,6 @@ index 49768734d..e1bc3e64e 100644
|
|||||||
- } catch ( Throwable t )
|
- } 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
|
+ // Check if we've actually hit a state where the server is going to safely shutdown
|
||||||
@ -303,5 +306,5 @@ index 49768734d..e1bc3e64e 100644
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
--
|
--
|
||||||
2.13.0.windows.1
|
2.13.1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user