next try for a better restart

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3941 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 18 years ago
parent 110a1a2b16
commit 19786b73b6

@ -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());

@ -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);
}
}
*/
}

Loading…
Cancel
Save