Skip to content

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

next try for a better restart

orbiter19786b73b6ea
diff --git a/source/de/anomic/server/serverSystem.java b/source/de/anomic/server/serverSystem.java
index a4e758af1..66636b50e 100644
--- a/source/de/anomic/server/serverSystem.java
+++ b/source/de/anomic/server/serverSystem.java
@@ -48,6 +48,10 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Hashtable;
import java.util.Properties;
+import java.util.Vector;
+
+import de.anomic.plasma.plasmaSwitchboard;
+import de.anomic.server.logging.serverLog;
public final class serverSystem {
@@ -326,6 +330,40 @@ public final class serverSystem {
}
}
+ public static void deployScript(File scriptFile, String theScript) throws IOException {
+ serverFileUtils.write(theScript.getBytes(), scriptFile);
+ try {
+ Runtime.getRuntime().exec("chmod 755 " + scriptFile.getAbsolutePath()).waitFor();
+ } catch (InterruptedException e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ public static void execAsynchronous(File scriptFile) throws IOException {
+ // runs a unix/linux script as separate thread
+ File starterFile = new File(scriptFile.getAbsolutePath() + ".starter.sh");
+ deployScript(starterFile, scriptFile.getAbsolutePath() + " &");
+ try {
+ Runtime.getRuntime().exec(starterFile.getAbsolutePath()).waitFor();
+ } catch (InterruptedException e) {
+ throw new IOException(e.getMessage());
+ }
+ starterFile.delete();
+ }
+
+ public static Vector execSynchronous(String command) throws IOException {
+ // runs a unix/linux command and returns output as Vector of Strings
+ // this method blocks until the command is executed
+ Process p = Runtime.getRuntime().exec(command);
+ BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ String text;
+ Vector output = new Vector();
+ while ((text = in.readLine()) != null) {
+ output.add(text);
+ }
+ return output;
+ }
+
public static void main(String[] args) {
//try{System.getProperties().list(new PrintStream(new FileOutputStream(new File("system.properties.txt"))));} catch (FileNotFoundException e) {}
//System.out.println("nullstr=" + macMRJOSNullObj.toString());
diff --git a/source/de/anomic/yacy/yacyVersion.java b/source/de/anomic/yacy/yacyVersion.java
index 9011a0206..f51e2334e 100644
--- a/source/de/anomic/yacy/yacyVersion.java
+++ b/source/de/anomic/yacy/yacyVersion.java
@@ -283,7 +283,23 @@ public final class yacyVersion implements Comparator, Comparable {
}
}
-
+
+ if (serverSystem.canExecUnix) {
+ // start a re-start daemon
+ try {
+ serverLog.logInfo("RESTART", "INITIATED");
+ String script = "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");
+ serverSystem.deployScript(scriptFile, script);
+ serverLog.logInfo("RESTART", "wrote restart-script to " + scriptFile.getAbsolutePath());
+ serverSystem.execAsynchronous(scriptFile);
+ serverLog.logInfo("RESTART", "script is running");
+ plasmaSwitchboard.getSwitchboard().terminate(5000);
+ } catch (IOException e) {
+ serverLog.logSevere("RESTART", "restart failed", e);
+ }
+ }
+/*
if (serverSystem.canExecUnix) {
// start a re-start daemon
try {
@@ -293,13 +309,7 @@ public final class yacyVersion implements Comparator, Comparable {
serverFileUtils.write(script.getBytes(), scriptFile);
serverLog.logInfo("RESTART", "wrote restart-script to " + scriptFile.getAbsolutePath());
Runtime.getRuntime().exec("chmod 755 " + scriptFile.getAbsolutePath()).waitFor();
- /*Process p =*/ Runtime.getRuntime().exec(scriptFile.getAbsolutePath() + " &");
- /*serverLog.logInfo("RESTART", "script started");
- BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
- String text;
- while ((text = in.readLine()) != null) {
- serverLog.logInfo("RESTART", " SCRIPT-LOG " + text);
- }*/
+ Runtime.getRuntime().exec(scriptFile.getAbsolutePath() + " &");
serverLog.logInfo("RESTART", "script is running");
plasmaSwitchboard.getSwitchboard().terminate(5000);
} catch (IOException e) {
@@ -308,6 +318,7 @@ public final class yacyVersion implements Comparator, Comparable {
serverLog.logSevere("RESTART", "restart failed", e);
}
}
+*/
}