3
0

Support to restart server after update

This commit is contained in:
Prototik 2015-06-14 19:50:18 +07:00
parent 55d1d750ec
commit 44020ecc25
7 changed files with 56 additions and 30 deletions

View File

@ -1795,7 +1795,7 @@
{ {
packetbuffer = new PacketBuffer(Unpooled.wrappedBuffer(p_147349_1_.func_149558_e())); packetbuffer = new PacketBuffer(Unpooled.wrappedBuffer(p_147349_1_.func_149558_e()));
@@ -1093,16 +2398,18 @@ @@ -1093,16 +2398,18 @@
{
if (itemstack.getItem() == Items.writable_book && itemstack.getItem() == itemstack1.getItem()) if (itemstack.getItem() == Items.writable_book && itemstack.getItem() == itemstack1.getItem())
{ {
- itemstack1.setTagInfo("pages", itemstack.getTagCompound().getTagList("pages", 8)); - itemstack1.setTagInfo("pages", itemstack.getTagCompound().getTagList("pages", 8));

View File

@ -6,11 +6,14 @@ import java.net.URLDecoder;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Properties; import java.util.Properties;
import org.spigotmc.RestartCommand;
public class KCauldron { public class KCauldron {
private static boolean sManifestParsed = false; private static boolean sManifestParsed = false;
private static void parseManifest() { private static void parseManifest() {
if (sManifestParsed) return; if (sManifestParsed)
return;
sManifestParsed = true; sManifestParsed = true;
try { try {
@ -23,9 +26,10 @@ public class KCauldron {
String version = manifest.getProperty("KCauldron-Version"); String version = manifest.getProperty("KCauldron-Version");
if (version != null) { if (version != null) {
String path = url.getPath(); String path = url.getPath();
String jarFilePath = path.substring(path.indexOf(":") + 1, path.indexOf("!")); String jarFilePath = path.substring(path.indexOf(":") + 1,
jarFilePath = URLDecoder.decode(jarFilePath, "UTF-8"); path.indexOf("!"));
sServerLocation = new File(jarFilePath); jarFilePath = URLDecoder.decode(jarFilePath, "UTF-8");
sServerLocation = new File(jarFilePath);
sCurrentVersion = version; sCurrentVersion = version;
sBranch = manifest.getProperty("KCauldron-Branch"); sBranch = manifest.getProperty("KCauldron-Branch");
@ -70,4 +74,8 @@ public class KCauldron {
public static File sNewServerLocation; public static File sNewServerLocation;
public static String sNewServerVersion; public static String sNewServerVersion;
public static boolean sUpdateInProgress; public static boolean sUpdateInProgress;
public static void restart() {
RestartCommand.restart(true);
}
} }

View File

@ -1,5 +1,7 @@
package kcauldron; package kcauldron;
import static org.objectweb.asm.Opcodes.*;
import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Level;
import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassVisitor;
@ -11,19 +13,9 @@ import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.InsnNode; import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.IntInsnNode; import org.objectweb.asm.tree.IntInsnNode;
import pw.prok.imagine.api.Pair;
import pw.prok.imagine.asm.ImagineASM; import pw.prok.imagine.asm.ImagineASM;
import pw.prok.imagine.asm.ImagineMethod;
import pw.prok.imagine.asm.ImagineRemapper;
import pw.prok.imagine.asm.Transformer; import pw.prok.imagine.asm.Transformer;
import com.avaje.ebean.annotation.Transactional;
import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.FMLLog;
import net.minecraft.launchwrapper.IClassTransformer;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.IChunkProvider;
import static org.objectweb.asm.Opcodes.*;
@Transformer.RegisterTransformer @Transformer.RegisterTransformer
public class KCauldronClassTransformer implements Transformer { public class KCauldronClassTransformer implements Transformer {

View File

@ -9,16 +9,20 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class KCauldronCommand extends Command { public class KCauldronCommand extends Command {
public static final String NAME = "kcauldron"; public static final String NAME = "kc";
public static final String CHECK = NAME + ".check"; public static final String CHECK = NAME + ".check";
public static final String UPDATE = NAME + ".update"; public static final String UPDATE = NAME + ".update";
public static final String RESTART = NAME + ".restart";
public KCauldronCommand() { public KCauldronCommand() {
super(NAME); super(NAME);
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append(String.format("/%s check\n", NAME)); builder.append(String.format("/%s check - Check to update\n", NAME));
builder.append(String.format("/%s update [version]\n", NAME)); builder.append(String
.format("/%s update [version] - Update to specified or latest version\n",
NAME));
builder.append(String.format("/%s restart - Restart server\n", NAME));
setUsage(builder.toString()); setUsage(builder.toString());
setPermission("kcauldron"); setPermission("kcauldron");
@ -50,6 +54,7 @@ public class KCauldronCommand extends Command {
return true; return true;
if (args.length == 0) { if (args.length == 0) {
sender.sendMessage(ChatColor.YELLOW + "Please specify action"); sender.sendMessage(ChatColor.YELLOW + "Please specify action");
sender.sendMessage(ChatColor.AQUA + usageMessage);
return true; return true;
} }
String action = args[0]; String action = args[0];
@ -62,6 +67,10 @@ public class KCauldronCommand extends Command {
} else if ("update".equals(action)) { } else if ("update".equals(action)) {
KCauldronUpdater.initUpdate(sender, args.length > 1 ? args[1] KCauldronUpdater.initUpdate(sender, args.length > 1 ? args[1]
: null); : null);
} else if ("restart".equals(action)) {
if (!testPermission(sender, RESTART))
return true;
KCauldron.restart();
} else { } else {
sender.sendMessage(ChatColor.RED + "Unknown action"); sender.sendMessage(ChatColor.RED + "Unknown action");
} }

View File

@ -19,13 +19,15 @@ public class KCauldronConfig extends ConfigBase {
"updatechecker.symlinks", "", "(Re)create symlinks after update"); "updatechecker.symlinks", "", "(Re)create symlinks after update");
public BoolSetting updatecheckerAutoinstall = new BoolSetting(this, public BoolSetting updatecheckerAutoinstall = new BoolSetting(this,
"updatechecker.autoinstall", false, "Install updates without confirming"); "updatechecker.autoinstall", false, "Install updates without confirming");
public BoolSetting updatecheckerAutorestart = new BoolSetting(this,
"updatechecker.autorestart", false, "Restart server after updating without confirming (set restart script in spigot.yml)");
public BoolSetting updatecheckerQuite = new BoolSetting(this, public BoolSetting updatecheckerQuite = new BoolSetting(this,
"updatechecker.quite", false, "Print less info during update"); "updatechecker.quite", false, "Print less info during update");
public StringSetting updatecheckerInstallAs = new StringSetting(this, public StringSetting updatecheckerInstallAs = new StringSetting(this,
"updatechecker.installAs", "", "Install new version with specified name"); "updatechecker.installAs", "", "Install new version with specified name");
public BoolSetting loggingMaterialInjection = new BoolSetting(this, public BoolSetting loggingMaterialInjection = new BoolSetting(this,
"loggin.materialInjection", false, "Log material injection event"); "logging.materialInjection", false, "Log material injection event");
public KCauldronConfig() { public KCauldronConfig() {
super("kcauldron.yml", "kc"); super("kcauldron.yml", "kc");
@ -34,6 +36,7 @@ public class KCauldronConfig extends ConfigBase {
register(updatecheckerDeleteOld); register(updatecheckerDeleteOld);
register(updatecheckerSymlinks); register(updatecheckerSymlinks);
register(updatecheckerAutoinstall); register(updatecheckerAutoinstall);
register(updatecheckerAutorestart);
register(updatecheckerQuite); register(updatecheckerQuite);
register(updatecheckerInstallAs); register(updatecheckerInstallAs);
register(loggingMaterialInjection); register(loggingMaterialInjection);

View File

@ -152,6 +152,12 @@ public class KCauldronUpdater implements Runnable {
} }
KCauldron.sNewServerLocation = newPath; KCauldron.sNewServerLocation = newPath;
KCauldron.sNewServerVersion = mVersion; KCauldron.sNewServerVersion = mVersion;
if (MinecraftServer.kcauldronConfig.updatecheckerAutorestart.getValue()) {
if (mSender != null) {
mSender.sendMessage(ChatColor.DARK_RED + "Initiate server restart");
}
KCauldron.restart();
}
} catch (Exception e) { } catch (Exception e) {
if (!quite) { if (!quite) {
e.printStackTrace(); e.printStackTrace();

View File

@ -27,7 +27,11 @@ public class RestartCommand extends Command
return true; return true;
} }
public static void restart() public static void restart() {
restart(false);
}
public static void restart(boolean forbidShutdown)
{ {
try try
{ {
@ -98,9 +102,13 @@ public class RestartCommand extends Command
Runtime.getRuntime().addShutdownHook( shutdownHook ); Runtime.getRuntime().addShutdownHook( shutdownHook );
} else } else
{ {
if (forbidShutdown) {
System.out.println("Attempt to restart server without restart script, decline request");
return;
}
System.out.println( "Startup script '" + SpigotConfig.restartScript + "' does not exist! Stopping server." ); System.out.println( "Startup script '" + SpigotConfig.restartScript + "' does not exist! Stopping server." );
} }
System.exit( 0 ); cpw.mods.fml.common.FMLCommonHandler.instance().exitJava(0, false);
} catch ( Exception ex ) } catch ( Exception ex )
{ {
ex.printStackTrace(); ex.printStackTrace();