From 2ff94b2fb45bb0ee141ccd5757d12c263795e2f8 Mon Sep 17 00:00:00 2001 From: orbiter Date: Fri, 29 Jun 2007 13:56:28 +0000 Subject: [PATCH] another try to fix the restart on linux (it works on mac) git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3938 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/Status.java | 10 ++++-- htroot/Steering.java | 34 ++------------------ restart.sh | 16 ---------- source/de/anomic/yacy/yacyVersion.java | 43 +++++++++++++++++++++++++- 4 files changed, 52 insertions(+), 51 deletions(-) delete mode 100755 restart.sh diff --git a/htroot/Status.java b/htroot/Status.java index abce5fe74..9e2fab7db 100644 --- a/htroot/Status.java +++ b/htroot/Status.java @@ -46,6 +46,7 @@ // javac -classpath .:../Classes Status.java // if the shell's current path is HTROOT +import java.io.File; import java.io.IOException; import java.text.DecimalFormat; import java.util.Date; @@ -174,8 +175,13 @@ public class Status { String[] downloaded = sb.releasePath.list(); TreeSet downloadedreleases = new TreeSet(); for (int j = 0; j < downloaded.length; j++) { - release = (yacyVersion) new yacyVersion(downloaded[j]); - downloadedreleases.add(release); + try { + release = (yacyVersion) new yacyVersion(downloaded[j]); + downloadedreleases.add(release); + } catch (RuntimeException e) { + // not a valid release + new File(sb.releasePath, downloaded[j]).deleteOnExit(); // can be also a restart- or deploy-file + } } dflt = (downloadedreleases.size() == 0) ? null : (yacyVersion) downloadedreleases.last(); Iterator i = downloadedreleases.iterator(); diff --git a/htroot/Steering.java b/htroot/Steering.java index 459192ef3..bcc19d9dc 100644 --- a/htroot/Steering.java +++ b/htroot/Steering.java @@ -46,17 +46,11 @@ // javac -classpath .:../Classes SettingsAck_p.java // if the shell's current path is HTROOT -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; - import de.anomic.http.httpHeader; import de.anomic.plasma.plasmaSwitchboard; import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; -import de.anomic.server.logging.serverLog; -import de.anomic.server.serverSystem; +import de.anomic.yacy.yacyVersion; public class Steering { @@ -81,31 +75,7 @@ public class Steering { } if (post.containsKey("restart")) { - if (System.getProperty("os.name").toLowerCase().startsWith("win")) { - // create yacy.restart file which is used in Windows startscript - final File yacyRestart = new File(sb.getRootPath(), "DATA/yacy.restart"); - if (!yacyRestart.exists()) { - try { - yacyRestart.createNewFile(); - } catch (IOException e) { - serverLog.logConfig("SHUTDOWN", "ERROR: no restart !"); - e.printStackTrace(); - } - } - } else if (serverSystem.canExecUnix) { - // start a re-start daemon - try { - Process p = Runtime.getRuntime().exec("source " + sb.getRootPath() + "/restart.sh " + sb.getRootPath() + " &"); - BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); - String text; - while ((text = in.readLine()) != null) { - sb.getLog().logInfo("RESTART -- " + text); - } - } catch (IOException e) { - sb.getLog().logSevere("restart failed", e); - } - } - sb.terminate(5000); + yacyVersion.restart(); prop.put("info", 4); return prop; diff --git a/restart.sh b/restart.sh deleted file mode 100755 index 274d8921f..000000000 --- a/restart.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -# this is the restart process script that is started from YaCy -# in case that YaCy is terminated with the restart option - -# navigate into the own directory path -# the path is handed over upon start of this script -cd $1 - -# waiting for shutdown -while [ -e DATA/yacy.running ]; do -sleep 1 -done - -# shutdown complete, start up yacy -./startYACY.sh diff --git a/source/de/anomic/yacy/yacyVersion.java b/source/de/anomic/yacy/yacyVersion.java index 784f99bb4..10294c99a 100644 --- a/source/de/anomic/yacy/yacyVersion.java +++ b/source/de/anomic/yacy/yacyVersion.java @@ -27,8 +27,10 @@ package de.anomic.yacy; +import java.io.BufferedReader; import java.io.File; import java.io.IOException; +import java.io.InputStreamReader; import java.net.MalformedURLException; import java.util.Comparator; import java.util.Iterator; @@ -39,7 +41,10 @@ import de.anomic.htmlFilter.htmlFilterContentScraper; import de.anomic.http.httpc; import de.anomic.net.URL; import de.anomic.plasma.plasmaSwitchboard; +import de.anomic.server.serverCore; import de.anomic.server.serverFileUtils; +import de.anomic.server.serverSystem; +import de.anomic.server.logging.serverLog; public final class yacyVersion implements Comparator, Comparable { @@ -264,8 +269,44 @@ public final class yacyVersion implements Comparator, Comparable { serverFileUtils.write(file, new File(storagePath, release.url.getFileName())); } + + public static void restart() { + if (System.getProperty("os.name").toLowerCase().startsWith("win")) { + // create yacy.restart file which is used in Windows startscript + final File yacyRestart = new File(plasmaSwitchboard.getSwitchboard().getRootPath(), "DATA/yacy.restart"); + if (!yacyRestart.exists()) { + try { + yacyRestart.createNewFile(); + plasmaSwitchboard.getSwitchboard().terminate(5000); + } catch (IOException e) { + serverLog.logSevere("SHUTDOWN", "restart failed", e); + } + } + + } + + if (serverSystem.canExecUnix) { + // start a re-start daemon + try { + String script = "#!/bin/sh" + serverCore.crlfString + "cd " + plasmaSwitchboard.getSwitchboard().getRootPath() + "/DATA/RELEASE/;while [ -e ../yacy.running ]; do sleep 1;done;cd ../../;./startYACY.sh"; + File scriptFile = new File(plasmaSwitchboard.getSwitchboard().getRootPath(), "DATA/RELEASE/restart.sh"); + serverFileUtils.write(script.getBytes(), scriptFile); + Process p = Runtime.getRuntime().exec("/bin/sh chmod 755 " + scriptFile.getAbsolutePath() + ";" + scriptFile.getAbsolutePath() + " &"); + BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); + String text; + while ((text = in.readLine()) != null) { + serverLog.logInfo("RESTART", " -- " + text); + } + plasmaSwitchboard.getSwitchboard().terminate(5000); + } catch (IOException e) { + serverLog.logSevere("RESTART", "restart failed", e); + } + } + } + + public static void writeDeployScript(String release) { - byte[] script = ("cd `dirname $0`;while [ -e ../yacy.running ]; do sleep 1;done;tar xfz " + release + ";cp -Rf yacy/* ../../;rm -Rf yacy;cd ../../;startYACY.sh").getBytes(); + //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(); } }