Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

fix for bad deploy: - the name of downloaded release files is adopted if the httpc delivers uncompressed tar.gz files (the .gz is removed from the file name) - the deploy method is able to handle tar-file (not tar.gz-files)

orbiter5d1fbb25e7ae
diff --git a/htroot/ConfigUpdate_p.java b/htroot/ConfigUpdate_p.java
index 8ec5894cb..e5a31f363 100644
--- a/htroot/ConfigUpdate_p.java
+++ b/htroot/ConfigUpdate_p.java
@@ -89,18 +89,17 @@ public class ConfigUpdate_p {
} else {
// there is a version that is more recent. Load it and re-start with it
sb.getLog().logInfo("AUTO-UPDATE: downloading more recent release " + updateVersion.url);
- boolean downloaded = yacyVersion.downloadRelease(updateVersion);
+ File downloaded = yacyVersion.downloadRelease(updateVersion);
prop.put("candeploy_autoUpdate_downloadedRelease", updateVersion.name);
- File releaseFile = new File(sb.getRootPath(), "DATA/RELEASE/" + updateVersion.name);
boolean devenvironment = yacyVersion.combined2prettyVersion(sb.getConfig("version","0.1")).startsWith("dev");
if (devenvironment) {
sb.getLog().logInfo("AUTO-UPDATE: omiting update because this is a development environment");
prop.put("candeploy_autoUpdate", "3");
- } else if ((!downloaded) || (!releaseFile.exists()) || (releaseFile.length() == 0)) {
+ } else if ((downloaded == null) || (!downloaded.exists()) || (downloaded.length() == 0)) {
sb.getLog().logInfo("AUTO-UPDATE: omiting update because download failed (file cannot be found or is too small)");
prop.put("candeploy_autoUpdate", "4");
} else {
- yacyVersion.deployRelease(updateVersion.name);
+ yacyVersion.deployRelease(downloaded);
sb.terminate(5000);
sb.getLog().logInfo("AUTO-UPDATE: deploy and restart initiated");
prop.put("candeploy_autoUpdate", "1");
diff --git a/htroot/Steering.java b/htroot/Steering.java
index c67cc08d5..b9f8f0a49 100644
--- a/htroot/Steering.java
+++ b/htroot/Steering.java
@@ -88,7 +88,7 @@ public class Steering {
String releaseFileName = post.get("releaseinstall", "");
File releaseFile = new File(sb.getRootPath(), "DATA/RELEASE/" + releaseFileName);
if ((!devenvironment) && (releaseFile.length() > 0) && (releaseFile.exists())) {
- yacyVersion.deployRelease(releaseFileName);
+ yacyVersion.deployRelease(releaseFile);
}
prop.put("info", "5");
prop.put("info_release", releaseFileName);
diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.java
index bab13f471..0a0b4e321 100644
--- a/source/de/anomic/plasma/plasmaSwitchboard.java
+++ b/source/de/anomic/plasma/plasmaSwitchboard.java
@@ -2012,15 +2012,14 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<plasmaSwitchbo
if (updateVersion != null) {
// there is a version that is more recent. Load it and re-start with it
log.logInfo("AUTO-UPDATE: downloading more recent release " + updateVersion.url);
- boolean downloaded = yacyVersion.downloadRelease(updateVersion);
- File releaseFile = new File(sb.getRootPath(), "DATA/RELEASE/" + updateVersion.name);
+ File downloaded = yacyVersion.downloadRelease(updateVersion);
boolean devenvironment = yacyVersion.combined2prettyVersion(sb.getConfig("version","0.1")).startsWith("dev");
if (devenvironment) {
log.logInfo("AUTO-UPDATE: omiting update because this is a development environment");
- } else if ((!downloaded) || (!releaseFile.exists()) || (releaseFile.length() == 0)) {
+ } else if ((downloaded == null) || (!downloaded.exists()) || (downloaded.length() == 0)) {
log.logInfo("AUTO-UPDATE: omiting update because download failed (file cannot be found or is too small)");
} else {
- yacyVersion.deployRelease(updateVersion.name);
+ yacyVersion.deployRelease(downloaded);
terminate(5000);
log.logInfo("AUTO-UPDATE: deploy and restart initiated");
}
diff --git a/source/de/anomic/yacy/yacyVersion.java b/source/de/anomic/yacy/yacyVersion.java
index f712872ee..eb3ca76ed 100644
--- a/source/de/anomic/yacy/yacyVersion.java
+++ b/source/de/anomic/yacy/yacyVersion.java
@@ -326,14 +326,21 @@ public final class yacyVersion implements Comparator<yacyVersion>, Comparable<ya
return new DevMain(devreleases, mainreleases);
}
- public static boolean downloadRelease(yacyVersion release) {
+ public static File downloadRelease(yacyVersion release) {
File storagePath = plasmaSwitchboard.getSwitchboard().releasePath;
// load file
- File download = new File(storagePath, release.url.getFileName());
+ File download = null;
JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(120000, null, null);
JakartaCommonsHttpResponse res = null;
+ String name = release.url.getFileName();
try {
res = client.GET(release.url.toString());
+ boolean unzipped = res.getResponseHeader().gzip() && (res.getResponseHeader().mime().toLowerCase().equals("application/x-tar")); // if true, then the httpc has unzipped the file
+ if ((unzipped) && (name.endsWith(".tar.gz"))) {
+ download = new File(storagePath, name.substring(0, name.length() - 3));
+ } else {
+ download = new File(storagePath, name);
+ }
try {
serverFileUtils.copyToStream(new BufferedInputStream(res.getDataAsStream()), new BufferedOutputStream(new FileOutputStream(download)));
} finally {
@@ -343,6 +350,7 @@ public final class yacyVersion implements Comparator<yacyVersion>, Comparable<ya
} catch (IOException e) {
serverLog.logSevere("yacyVersion", "download of " + release.name + " failed: " + e.getMessage());
if (download.exists()) download.delete();
+ download = null;
} finally {
if (res != null) {
// release connection
@@ -350,7 +358,7 @@ public final class yacyVersion implements Comparator<yacyVersion>, Comparable<ya
}
}
plasmaSwitchboard.getSwitchboard().setConfig("update.time.download", System.currentTimeMillis());
- return download.exists();
+ return download;
}
@@ -395,7 +403,7 @@ public final class yacyVersion implements Comparator<yacyVersion>, Comparable<ya
}
}
- public static void deployRelease(String release) {
+ public static void deployRelease(File releaseFile) {
//byte[] script = ("cd " + plasmaSwitchboard.getSwitchboard().getRootPath() + ";while [ -e ../yacy.running ]; do sleep 1;done;tar xfz " + release + ";cp -Rf yacy/* ../../;rm -Rf yacy;cd ../../;startYACY.sh").getBytes();
try {
plasmaSwitchboard sb = plasmaSwitchboard.getSwitchboard();
@@ -404,9 +412,12 @@ public final class yacyVersion implements Comparator<yacyVersion>, Comparable<ya
String script =
"#!/bin/sh" + serverCore.LF_STRING +
"cd " + sb.getRootPath() + "/DATA/RELEASE/" + serverCore.LF_STRING +
- "if gunzip -t " + release + serverCore.LF_STRING +
- "then" + serverCore.LF_STRING +
- "gunzip -c " + release + " | tar xf -" + serverCore.LF_STRING +
+ ((releaseFile.getName().endsWith(".gz")) ?
+ ("if gunzip -t " + releaseFile.getAbsolutePath() + serverCore.LF_STRING +
+ "then" + serverCore.LF_STRING +
+ "gunzip -c " + releaseFile.getAbsolutePath() + " | tar xf -" + serverCore.LF_STRING) :
+ ("tar xf " + releaseFile.getAbsolutePath() + serverCore.LF_STRING)
+ ) +
"while [ -f ../yacy.running ]; do" + serverCore.LF_STRING +
"sleep 1" + serverCore.LF_STRING +
"done" + serverCore.LF_STRING +