* automatic update for windows

pleas disable before release because 2nd update fails at the moment
and commandline handling has to be improved for windows
* update via new unTar class
please review stream- and exceptionhandling because I'm fairly new to Java
maybe it can be done concurrent
* updated windows startscripts to values from yacy.init

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4832 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
lotus 17 years ago
parent faed00d75d
commit 4a48717017

@ -10,9 +10,11 @@
#%env/templates/submenuConfig.template%# #%env/templates/submenuConfig.template%#
<h2>System Update</h2> <h2>System Update</h2>
#(deploys)#::Release will be installed. Please wait.#(/deploys)#
#(candeploy)# #(candeploy)#
This servlet can only be used on operation systems that are currently supported for deploy functions. This servlet can only be used on operation systems that are currently supported for deploy functions.
If you see this message this means that your operation sytem ist not supported. If you see this message this means that your operation system is not supported.
:: ::
<fieldset> <fieldset>
<legend>Manual System Update</legend> <legend>Manual System Update</legend>
@ -100,6 +102,7 @@
<dt>Last Deploy</dt><dd><p>#(lastdeploy)#never::#[time]##(/lastdeploy)#</p></dd> <dt>Last Deploy</dt><dd><p>#(lastdeploy)#never::#[time]##(/lastdeploy)#</p></dd>
</dl> </dl>
</fieldset> </fieldset>
::
#(/candeploy)# #(/candeploy)#
#%env/templates/footer.template%# #%env/templates/footer.template%#

@ -52,6 +52,8 @@ public class ConfigUpdate_p {
if (post.containsKey("update")) { if (post.containsKey("update")) {
prop.put("forwardToSteering", "1"); prop.put("forwardToSteering", "1");
prop.put("forwardToSteering_release",post.get("releaseinstall", "")); prop.put("forwardToSteering_release",post.get("releaseinstall", ""));
prop.put("deploys", "1");
prop.put("candeploy", "2"); // display nothing else
return prop; return prop;
} }
@ -117,7 +119,7 @@ public class ConfigUpdate_p {
} }
// set if this should be visible // set if this should be visible
if (serverSystem.canExecUnix) { if (serverSystem.canExecUnix || serverSystem.isWindows) {
// we can deploy a new system with (i.e.) // we can deploy a new system with (i.e.)
// cd DATA/RELEASE;tar xfz $1;cp -Rf yacy/* ../../;rm -Rf yacy // cd DATA/RELEASE;tar xfz $1;cp -Rf yacy/* ../../;rm -Rf yacy
prop.put("candeploy", "1"); prop.put("candeploy", "1");

@ -86,7 +86,7 @@ public class Steering {
if (post.containsKey("update")) { if (post.containsKey("update")) {
boolean devenvironment = yacyVersion.combined2prettyVersion(sb.getConfig("version","0.1")).startsWith("dev"); boolean devenvironment = yacyVersion.combined2prettyVersion(sb.getConfig("version","0.1")).startsWith("dev");
String releaseFileName = post.get("releaseinstall", ""); String releaseFileName = post.get("releaseinstall", "");
File releaseFile = new File(sb.getRootPath(), "DATA/RELEASE/" + releaseFileName); File releaseFile = new File(sb.getRootPath(), "DATA/RELEASE/".replace("/", File.separator) + releaseFileName);
if ((!devenvironment) && (releaseFile.length() > 0) && (releaseFile.exists())) { if ((!devenvironment) && (releaseFile.length() > 0) && (releaseFile.exists())) {
yacyVersion.deployRelease(releaseFile); yacyVersion.deployRelease(releaseFile);
} }

@ -224,7 +224,6 @@ public class yacysearchitem {
((yacyURL.probablyRootURL(result.hash())) ? ", probablyRootURL" : "") + ((yacyURL.probablyRootURL(result.hash())) ? ", probablyRootURL" : "") +
(((wordURL = yacyURL.probablyWordURL(result.hash(), query[0])) != null) ? ", probablyWordURL=" + wordURL.toNormalform(false, true) : "")); (((wordURL = yacyURL.probablyWordURL(result.hash(), query[0])) != null) ? ", probablyWordURL=" + wordURL.toNormalform(false, true) : ""));
plasmaSnippetCache.TextSnippet snippet = result.textSnippet(); plasmaSnippetCache.TextSnippet snippet = result.textSnippet();
// TODO: check if tags are correctly stripped from snippet
prop.put("content_snippet", (snippet == null) ? "(snippet not found)" : snippet.getLineMarked(theQuery.queryHashes)); prop.put("content_snippet", (snippet == null) ? "(snippet not found)" : snippet.getLineMarked(theQuery.queryHashes));
serverProfiling.update("SEARCH", new plasmaProfiling.searchEvent(theQuery.id(true), plasmaSearchEvent.FINALIZATION + "-" + item, 0, 0)); serverProfiling.update("SEARCH", new plasmaProfiling.searchEvent(theQuery.id(true), plasmaSearchEvent.FINALIZATION + "-" + item, 0, 0));

@ -69,6 +69,7 @@ public final class serverSystem {
public static boolean isMacArchitecture = false; public static boolean isMacArchitecture = false;
public static boolean isUnixFS = false; public static boolean isUnixFS = false;
public static boolean canExecUnix = false; public static boolean canExecUnix = false;
public static boolean isWindows = false;
// calculated system constants // calculated system constants
public static int maxPathLength = 65535; public static int maxPathLength = 65535;
@ -100,6 +101,7 @@ public final class serverSystem {
isMacArchitecture = ((systemOS == systemMacOSC) || (systemOS == systemMacOSX)); isMacArchitecture = ((systemOS == systemMacOSC) || (systemOS == systemMacOSX));
isUnixFS = ((systemOS == systemMacOSX) || (systemOS == systemUnix)); isUnixFS = ((systemOS == systemMacOSX) || (systemOS == systemUnix));
canExecUnix = ((isUnixFS) || (!((systemOS == systemMacOSC) || (systemOS == systemWindows)))); canExecUnix = ((isUnixFS) || (!((systemOS == systemMacOSC) || (systemOS == systemWindows))));
isWindows = (systemOS == systemWindows);
// set up the MRJ Methods through reflection // set up the MRJ Methods through reflection
if (isMacArchitecture) try { if (isMacArchitecture) try {
@ -121,13 +123,13 @@ public final class serverSystem {
macMRJFileUtils = null; macMRJOSType = null; macMRJFileUtils = null; macMRJOSType = null;
} }
// set up maximum path length accoring to system // set up maximum path length according to system
if (systemOS == systemWindows) maxPathLength = 255; else maxPathLength = 65535; if (isWindows) maxPathLength = 255; else maxPathLength = 65535;
} }
public static boolean isWindows() { /* public static boolean isWindows() {
return systemOS == systemWindows; return systemOS == systemWindows;
} }*/
public static Object getMacOSTS(String s) { public static Object getMacOSTS(String s) {
if ((isMacArchitecture) && (macMRJFileUtils != null)) try { if ((isMacArchitecture) && (macMRJFileUtils != null)) try {
@ -330,6 +332,7 @@ public final class serverSystem {
public static void deployScript(File scriptFile, String theScript) throws IOException { public static void deployScript(File scriptFile, String theScript) throws IOException {
serverFileUtils.copy(theScript.getBytes(), scriptFile); serverFileUtils.copy(theScript.getBytes(), scriptFile);
if(!isWindows){ // set executable
try { try {
Runtime.getRuntime().exec("chmod 755 " + scriptFile.getAbsolutePath().replaceAll(" ", "\\ ")).waitFor(); Runtime.getRuntime().exec("chmod 755 " + scriptFile.getAbsolutePath().replaceAll(" ", "\\ ")).waitFor();
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -337,12 +340,22 @@ public final class serverSystem {
throw new IOException(e.getMessage()); throw new IOException(e.getMessage());
} }
} }
}
public static void execAsynchronous(File scriptFile) throws IOException { public static void execAsynchronous(File scriptFile) throws IOException {
// runs a unix/linux script as separate thread // runs a script as separate thread
File starterFile = new File(scriptFile.getAbsolutePath().replaceAll(" ", "\\ ") + ".starter.sh"); String starterFileExtension = null;
//deployScript(starterFile, "touch restart.starter.startet1"); String script = null;
deployScript(starterFile, "#!/bin/sh" + serverCore.LF_STRING + scriptFile.getAbsolutePath().replaceAll(" ", "\\ ") + " &" + serverCore.LF_STRING); if(isWindows){
starterFileExtension = ".starter.bat";
// TODO: use /K to debug
script = "start /MIN CMD /C " + scriptFile.getAbsolutePath().replaceAll(" ", "\\ ");
} else { // unix/linux
starterFileExtension = ".starter.sh";
script = "#!/bin/sh" + serverCore.LF_STRING + scriptFile.getAbsolutePath().replaceAll(" ", "\\ ") + " &" + serverCore.LF_STRING;
}
File starterFile = new File(scriptFile.getAbsolutePath().replaceAll(" ", "\\ ") + starterFileExtension);
deployScript(starterFile, script);
try { try {
Runtime.getRuntime().exec(starterFile.getAbsolutePath().replaceAll(" ", "\\ ")).waitFor(); Runtime.getRuntime().exec(starterFile.getAbsolutePath().replaceAll(" ", "\\ ")).waitFor();
} catch (InterruptedException e) { } catch (InterruptedException e) {

@ -0,0 +1,98 @@
// tarTools.java
// (C) 2007 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
// contributed by David Wieditz; d.wieditz@gmx.de
// first published 21.05.2008 on http://yacy.net
//
// This is a part of YaCy, a peer-to-peer based web search engine
//
// $LastChangedDate: $
// $LastChangedRevision: $
// $LastChangedBy: $
//
// LICENSE
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package de.anomic.tools;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.zip.GZIPInputStream;
import com.ice.tar.TarEntry;
import com.ice.tar.TarInputStream;
import de.anomic.server.logging.serverLog;
public class tarTools {
public static InputStream getInputStream(String tarFileName) throws Exception{
if(tarFileName.endsWith(".gz")){
return new GZIPInputStream(new FileInputStream(new File(tarFileName)));
} else {
return new FileInputStream(new File(tarFileName));
}
}
public static InputStream getInputStream(File tarFileName) throws Exception{
return getInputStream(tarFileName.toString());
}
/**
* untar for any archive, overwrites existing data
* @param in use getInputStream() for convenience
* @param untarDir destination path
* @throws Exception (IOException or FileNotFoundException)
*/
public static void unTar(InputStream in, String untarDir) throws Exception{
serverLog.logInfo("UNTAR", "starting");
if(new File(untarDir).exists()){
TarInputStream tin = new TarInputStream(in);
TarEntry tarEntry = tin.getNextEntry();
while(tarEntry != null){
File destPath = new File(untarDir + File.separator + tarEntry.getName());
if (!tarEntry.isDirectory()) {
new File(destPath.getParent()).mkdirs(); // create missing subdirectories
FileOutputStream fout = new FileOutputStream(destPath);
tin.copyEntryContents(fout);
fout.close();
} else {
destPath.mkdir();
}
tarEntry = tin.getNextEntry();
}
tin.close();
} else { // untarDir doesn't exist
serverLog.logWarning("UNTAR", "destination " + untarDir + " doesn't exist.");
}
serverLog.logInfo("UNTAR", "finished");
}
public static void main(String args[]){
// @arg0 source
// @arg1 destination
if(args.length == 2){
try {
unTar(getInputStream(args[0]), args[1]);
} catch (Exception e) {
System.out.println(e);
}
} else {
System.out.println("usage: <source> <destination>");
}
}
}

@ -50,6 +50,7 @@ import de.anomic.server.serverCore;
import de.anomic.server.serverFileUtils; import de.anomic.server.serverFileUtils;
import de.anomic.server.serverSystem; import de.anomic.server.serverSystem;
import de.anomic.server.logging.serverLog; import de.anomic.server.logging.serverLog;
import de.anomic.tools.tarTools;
public final class yacyVersion implements Comparator<yacyVersion>, Comparable<yacyVersion> { public final class yacyVersion implements Comparator<yacyVersion>, Comparable<yacyVersion> {
@ -370,7 +371,7 @@ public final class yacyVersion implements Comparator<yacyVersion>, Comparable<ya
public static void restart() { public static void restart() {
plasmaSwitchboard sb = plasmaSwitchboard.getSwitchboard(); plasmaSwitchboard sb = plasmaSwitchboard.getSwitchboard();
if (System.getProperty("os.name").toLowerCase().startsWith("win")) { if (serverSystem.isWindows) {
// create yacy.restart file which is used in Windows startscript // create yacy.restart file which is used in Windows startscript
final File yacyRestart = new File(sb.getRootPath(), "DATA/yacy.restart"); final File yacyRestart = new File(sb.getRootPath(), "DATA/yacy.restart");
if (!yacyRestart.exists()) { if (!yacyRestart.exists()) {
@ -414,23 +415,64 @@ public final class yacyVersion implements Comparator<yacyVersion>, Comparable<ya
plasmaSwitchboard sb = plasmaSwitchboard.getSwitchboard(); plasmaSwitchboard sb = plasmaSwitchboard.getSwitchboard();
String apphome = sb.getRootPath().toString(); String apphome = sb.getRootPath().toString();
serverLog.logInfo("UPDATE", "INITIATED"); serverLog.logInfo("UPDATE", "INITIATED");
String script = try{
tarTools.unTar(tarTools.getInputStream(releaseFile), sb.getRootPath() + "/DATA/RELEASE/".replace("/", File.separator));
} catch (Exception e){
serverLog.logSevere("UNTAR", "failed", e);
}
String script = null;
String scriptFileName = null;
if(serverSystem.isWindows){
script =
// TODO: does YaCy delete this file after 2nd update-shutdown? "Die Batchdatei kann nicht gefunden werden."
"@echo off" + serverCore.LF_STRING +
"title YaCy updater" + serverCore.LF_STRING +
"echo YACY UPDATER" + serverCore.LF_STRING +
"echo working..." + serverCore.LF_STRING +
"cd " + apphome + "/DATA/RELEASE/".replace("/", File.separator) + serverCore.LF_STRING +
":WAIT" + serverCore.LF_STRING +
"ping -n 2 127.0.0.1 >nul" + serverCore.LF_STRING +
"IF exist ..\\yacy.running goto WAIT" + serverCore.LF_STRING +
"IF not exist yacy goto NODATA" + serverCore.LF_STRING +
"cd yacy" + serverCore.LF_STRING +
"xcopy *.* " + apphome + " /E /Y >nul" + serverCore.LF_STRING +
// /E - all subdirectories
// /Y - don't ask
"cd .." + serverCore.LF_STRING +
"rd yacy /S /Q" + serverCore.LF_STRING +
// /S delete tree
// /Q don't ask
"goto END" + serverCore.LF_STRING +
":NODATA" + serverCore.LF_STRING +
"echo YACY UPDATER ERROR: NO UPDATE SOURCE FILES ON FILESYSTEM" + serverCore.LF_STRING +
"pause" + serverCore.LF_STRING +
":END" + serverCore.LF_STRING +
"cd " + apphome + serverCore.LF_STRING +
"start /MIN CMD /C startYACY.bat" + serverCore.LF_STRING;
scriptFileName = "update.bat";
} else { // unix/linux
script =
"#!/bin/sh" + serverCore.LF_STRING + "#!/bin/sh" + serverCore.LF_STRING +
"cd " + sb.getRootPath() + "/DATA/RELEASE/" + serverCore.LF_STRING + "cd " + sb.getRootPath() + "/DATA/RELEASE/" + serverCore.LF_STRING +
((releaseFile.getName().endsWith(".gz")) ? /* ((releaseFile.getName().endsWith(".gz")) ?
// test gz-file for integrity and tar xfz then // test gz-file for integrity and tar xfz then
("if gunzip -t " + releaseFile.getAbsolutePath() + serverCore.LF_STRING + ("if gunzip -t " + releaseFile.getAbsolutePath() + serverCore.LF_STRING +
"then" + serverCore.LF_STRING + "then" + serverCore.LF_STRING +
"gunzip -c " + releaseFile.getAbsolutePath() + " | tar xf -" + serverCore.LF_STRING) : "gunzip -c " + releaseFile.getAbsolutePath() + " | tar xf -" + serverCore.LF_STRING) :
// just tar xf the file, no integrity test possible? // just tar xf the file, no integrity test possible?
("tar xf " + releaseFile.getAbsolutePath() + serverCore.LF_STRING) ("tar xf " + releaseFile.getAbsolutePath() + serverCore.LF_STRING)
) + ) +*/
"while [ -f ../yacy.running ]; do" + serverCore.LF_STRING + "while [ -f ../yacy.running ]; do" + serverCore.LF_STRING +
"sleep 1" + serverCore.LF_STRING + "sleep 1" + serverCore.LF_STRING +
"done" + serverCore.LF_STRING + "done" + serverCore.LF_STRING +
"cp -Rf yacy/* " + apphome + serverCore.LF_STRING + "cp -Rf yacy/* " + apphome + serverCore.LF_STRING +
"rm -Rf yacy" + serverCore.LF_STRING + "rm -Rf yacy" + serverCore.LF_STRING +
((releaseFile.getName().endsWith(".gz")) ? /* ((releaseFile.getName().endsWith(".gz")) ?
// else-case of gunzip -t test: if failed, just restart // else-case of gunzip -t test: if failed, just restart
("else" + serverCore.LF_STRING + ("else" + serverCore.LF_STRING +
"while [ -f ../yacy.running ]; do" + serverCore.LF_STRING + "while [ -f ../yacy.running ]; do" + serverCore.LF_STRING +
@ -439,10 +481,12 @@ public final class yacyVersion implements Comparator<yacyVersion>, Comparable<ya
"fi" + serverCore.LF_STRING) : "fi" + serverCore.LF_STRING) :
// in case that we did not made the integrity test, there is no else case // in case that we did not made the integrity test, there is no else case
"" ""
) + ) +*/
"cd " + apphome + serverCore.LF_STRING + "cd " + apphome + serverCore.LF_STRING +
"nohup ./startYACY.sh > /dev/null" + serverCore.LF_STRING; "nohup ./startYACY.sh > /dev/null" + serverCore.LF_STRING;
File scriptFile = new File(sb.getRootPath(), "DATA/RELEASE/update.sh"); scriptFileName = "update.sh";
}
File scriptFile = new File(sb.getRootPath(), "DATA/RELEASE/".replace("/", File.separator) + scriptFileName);
serverSystem.deployScript(scriptFile, script); serverSystem.deployScript(scriptFile, script);
serverLog.logInfo("UPDATE", "wrote update-script to " + scriptFile.getAbsolutePath()); serverLog.logInfo("UPDATE", "wrote update-script to " + scriptFile.getAbsolutePath());
serverSystem.execAsynchronous(scriptFile); serverSystem.execAsynchronous(scriptFile);

@ -11,7 +11,7 @@ For %%X in (libx/*.jar) Do Call %0 CPGEN libx\%%X
REM Please change the "javastart" settings in the web-interface "Basic Configuration" -> "Advanced" REM Please change the "javastart" settings in the web-interface "Basic Configuration" -> "Advanced"
set jmx= set jmx=
set jms= set jms=
set javacmd=-Xmx64m -Xms10m set javacmd=-Xmx120m -Xms120m
set priolvl=0 set priolvl=0
set priority=/NORMAL set priority=/NORMAL
if exist DATA\SETTINGS\httpProxy.conf GoTo :RENAMEINDEX if exist DATA\SETTINGS\httpProxy.conf GoTo :RENAMEINDEX
@ -36,6 +36,7 @@ start "YaCy" %priority% /B /WAIT java %javacmd% -classpath %CLASSPATH% yacy
if not exist DATA\yacy.restart GoTo :END if not exist DATA\yacy.restart GoTo :END
del DATA\yacy.restart del DATA\yacy.restart
GoTo :GETSTARTOPTS
Rem PUBLIC is now freeworld (r4575) Rem PUBLIC is now freeworld (r4575)
:RENAMEINDEX :RENAMEINDEX

@ -11,7 +11,7 @@ For %%X in (libx/*.jar) Do Call %0 CPGEN libx\%%X
REM Please change the "javastart" settings in the web-interface "Basic Configuration" -> "Advanced" REM Please change the "javastart" settings in the web-interface "Basic Configuration" -> "Advanced"
set jmx= set jmx=
set jms= set jms=
set javacmd=-Xmx94m -Xms94m set javacmd=-Xmx120m -Xms120m
set priolvl=0 set priolvl=0
set priority=/NORMAL set priority=/NORMAL
if exist DATA\SETTINGS\httpProxy.conf GoTo :RENAMEINDEX if exist DATA\SETTINGS\httpProxy.conf GoTo :RENAMEINDEX

Loading…
Cancel
Save