Skip to content
Permalink
Browse files

Fixed (serious) backup bug

  • Loading branch information...
dries007 committed Mar 27, 2018
1 parent 1d7f64a commit 6bf2b55e8ea075e2e8952668399d84f3c9ed0821
@@ -16,7 +16,7 @@ apply plugin: "idea-utils"
archivesBaseName = "D3Backend"
group = "net.doubledoordev.backend"

version = "0.12.0"
version = "0.12.1"
if (System.getenv().BUILD_NUMBER != null) version += "." + System.getenv().BUILD_NUMBER

def vendor = "DoubleDoorDevelopment"
@@ -190,6 +190,9 @@ public static void main(String[] args) throws Exception
LOGGER.info("Use the help command for help.");

CommandHandler.init();

Runtime.getRuntime().addShutdownHook(new Thread(() -> shutdown(true), "shutdown-hook"));

for (Server server : SETTINGS.servers.values())
{
try
@@ -205,39 +208,52 @@ public static void main(String[] args) throws Exception
}
}

public static synchronized void shutdown()
public static synchronized void shutdown(boolean isShutdownHook)
{
running = false;

Cache.stop();
Settings.save();

LOGGER.info("Attempting graceful shutdown of all servers...");
for (final Server server : SETTINGS.servers.values())
{
if (server.getOnline())
{
LOGGER.info("Server " + server.getID() + " is still online.");
try
{
try
{
server.stopServer(CommandHandler.CMDCALLER, NAME + " shutdown!");
}
catch (Exception e)
{
server.getProcess().destroy();
}

LOGGER.info("Waiting for server " + server.getID() + " to shutdown...");
server.getProcess().waitFor();
}
catch (Exception e)
{
e.printStackTrace();
LOGGER.info("Something went wrong while waiting for server " + server.getID(), e);
}
server.stopServer(CommandHandler.CMDCALLER, NAME + " shutdown!");
}
}
LOGGER.info("Bye!");
Runtime.getRuntime().exit(0);

for (final Server server : SETTINGS.servers.values())
{
if (!server.getOnline()) continue;

try
{
LOGGER.info("Waiting for server " + server.getID() + " to shutdown...");
server.getProcess().waitFor();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}

for (final Server server : SETTINGS.servers.values())
{
if (server.getProcess() != null) server.getProcess().destroy();
}

for (final Server server : SETTINGS.servers.values())
{
if (server.getProcess() != null) server.getProcess().destroyForcibly();
}

if (!isShutdownHook)
{
LOGGER.info("Bye!");
Runtime.getRuntime().exit(0);
}
}
}
@@ -256,7 +256,7 @@ public void cmdVersion() throws CommandException
public void cmdShutdown(@Switch('f') boolean force) throws CommandException
{
if (force) System.exit(0);
Main.shutdown();
Main.shutdown(false);
}

@Command(aliases = {"command", "cmd"}, desc = "Send a command to one or more servers", usage = "<server ID (regex)> <message ...>", min = 2)
@@ -456,11 +456,12 @@ private void saveProperties() throws IOException
{
if (!propertiesFile.exists()) propertiesFile.createNewFile();

FileOutputStream outputStream = new FileOutputStream(propertiesFile);
Properties properties = getProperties();
properties.store(outputStream, "Modified by the backend");
propertiesFileLastModified = propertiesFile.lastModified();
outputStream.close();
try (FileOutputStream outputStream = new FileOutputStream(propertiesFile))
{
Properties properties = getProperties();
properties.store(outputStream, "Modified by the backend");
propertiesFileLastModified = propertiesFile.lastModified();
}

ServerPropertiesSocketApplication.sendUpdateToAll(this);
}
@@ -861,7 +862,17 @@ private void installDownloadedModpack(final IMethodCaller methodCaller, final Fi
BufferedReader inReader = new BufferedReader(new InputStreamReader(new PipedInputStream(out)));
worker.setLogger(new PrintStream(out));

new Thread(worker, ID.concat("-curseDownloader")).start();
new Thread(() -> {
worker.run();
try
{
out.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}, ID.concat("-curseDownloader")).start();

while (!worker.isDone())
{
@@ -1054,6 +1065,7 @@ public void startServer(IMethodCaller caller) throws Exception
printLine(line);
}
printLine("----=====##### SERVER PROCESS HAS ENDED #####=====-----");
reader.close();
instance.update();
}
catch (IOException e)
@@ -72,7 +72,7 @@ public void makeWorldBackup(IMethodCaller methodCaller) throws BackupException

public void doMakeWorldBackup(IMethodCaller methodCaller)
{
doBackup(methodCaller, new File(new File(server.getBackupFolder(), WORLD), BACKUP_SDF.format(new Date()) + ".zip"), new File(server.getFolder(), getWorldName()), ACCEPT_NONE_EXCEPT_BACKUP_FILTER);
doBackup(methodCaller, new File(new File(server.getBackupFolder(), WORLD), BACKUP_SDF.format(new Date()) + ".zip"), new File(server.getFolder(), getWorldName()), ACCEPT_BACKUP_FILTER);
}

public void makeAllOfTheBackup(IMethodCaller methodCaller) throws BackupException
@@ -84,7 +84,7 @@ public void makeAllOfTheBackup(IMethodCaller methodCaller) throws BackupExceptio

public void doMakeAllOfTheBackup(IMethodCaller methodCaller)
{
doBackup(methodCaller, new File(new File(server.getBackupFolder(), SERVER), BACKUP_SDF.format(new Date()) + ".zip"), server.getFolder(), ACCEPT_NONE_EXCEPT_BACKUP_FILTER);
doBackup(methodCaller, new File(new File(server.getBackupFolder(), SERVER), BACKUP_SDF.format(new Date()) + ".zip"), server.getFolder(), ACCEPT_BACKUP_FILTER);
}

public void makeBackup(IMethodCaller methodCaller, String dimid) throws BackupException
@@ -96,7 +96,7 @@ public void makeBackup(IMethodCaller methodCaller, String dimid) throws BackupEx

public void doMakeBackup(IMethodCaller methodCaller, String dimid)
{
doBackup(methodCaller, new File(new File(server.getBackupFolder(), dimid), BACKUP_SDF.format(new Date()) + ".zip"), getFolder(dimid), dimid.equals(OVERWORLD) ? DIM_ONLY_FILTER : ACCEPT_NONE_EXCEPT_BACKUP_FILTER);
doBackup(methodCaller, new File(new File(server.getBackupFolder(), dimid), BACKUP_SDF.format(new Date()) + ".zip"), getFolder(dimid), dimid.equals(OVERWORLD) ? DIM_ONLY_FILTER : ACCEPT_BACKUP_FILTER);
}

public File getFolder(String dimid)
@@ -86,7 +86,7 @@

public final static FilenameFilter ACCEPT_ALL_JAR_FILTER = (dir, name) -> FilenameUtils.getExtension(name).equals("jar");
public final static FilenameFilter ACCEPT_ALL_FILTER = (dir, name) -> !name.equalsIgnoreCase("eula.txt");
public final static FilenameFilter ACCEPT_NONE_EXCEPT_BACKUP_FILTER = (dir, name) -> !name.toLowerCase().contains("backup");
public final static FilenameFilter ACCEPT_BACKUP_FILTER = (dir, name) -> name.toLowerCase().contains("backup");
public final static FilenameFilter ACCEPT_FORGE_FILTER = (dir, name) -> (name.startsWith("forge") || name.startsWith("FTBserver")) && ACCEPT_ALL_JAR_FILTER.accept(dir, name);
public final static FilenameFilter ACCEPT_MINECRAFT_SERVER_FILTER = (dir, name) -> name.startsWith("minecraft_server") && ACCEPT_ALL_JAR_FILTER.accept(dir, name);

@@ -144,55 +144,24 @@ public static String getNowInBanFormat()

public static Tag<?> readRawNBT(File file, boolean compressed)
{
Tag<?> tag = null;
try
try (NBTInputStream ns = new NBTInputStream(new FileInputStream(file), compressed))
{
InputStream is = new FileInputStream(file);
NBTInputStream ns = new NBTInputStream(is, compressed);
try
{
tag = ns.readTag();
}
finally
{
try
{
ns.close();
}
catch (IOException ignored)
{

}
}
return ns.readTag();
}
catch (Exception ignored)
{

return null;
}
return tag;
}

public static void writeRawNBT(File file, boolean compressed, Tag<?> tag)
{
try
{
OutputStream is = new FileOutputStream(file);
NBTOutputStream ns = new NBTOutputStream(is, compressed);
try
try (NBTOutputStream ns = new NBTOutputStream(new FileOutputStream(file), compressed))
{
ns.writeTag(tag);
}
finally
{
try
{
ns.close();
}
catch (IOException ignored)
{

}
}
}
catch (Exception ignored)
{

0 comments on commit 6bf2b55

Please sign in to comment.
You can’t perform that action at this time.