catch TimeoutException during ping and do not delete yacy.conf during prereadconfigfile

found a situation after crash (reboot) with existing running semaphore but YaCy not running.
Ping generated exception which finally deleted the conf file (during pre-read procedure)
- change to ping (catch exception solved it)
- additionally removed delete yacy.conf file (if needed we need to make a backup)
pull/1/head
reger 11 years ago
parent dc14824814
commit 8284ea751a

@ -151,7 +151,6 @@ public class Scanner {
} }
if (access != Access.unknown) Scanner.this.services.put(this, access); if (access != Access.unknown) Scanner.this.services.put(this, access);
} }
} catch (final ExecutionException e) {
} catch (final OutOfMemoryError e) { } catch (final OutOfMemoryError e) {
} }
} }

@ -108,9 +108,9 @@ public class TimeoutRequest<E> {
* @param uri * @param uri
* @param timeout * @param timeout
* @return true if the server exists and replies within the given time-out * @return true if the server exists and replies within the given time-out
* @throws ExecutionException
*/ */
public static boolean ping(final String host, final int port, final int timeout) throws ExecutionException { public static boolean ping(final String host, final int port, final int timeout) {
try {
return new TimeoutRequest<Boolean>(new Callable<Boolean>() { return new TimeoutRequest<Boolean>(new Callable<Boolean>() {
@Override @Override
public Boolean call() { public Boolean call() {
@ -135,6 +135,10 @@ public class TimeoutRequest<E> {
} }
} }
}).call(timeout).booleanValue(); }).call(timeout).booleanValue();
} catch (ExecutionException ex) { // may happen on Timeout (see call)
return false;
}
} }
/** /**

@ -74,12 +74,10 @@ public class migration {
// ssl/https support currently on hardcoded default port 8443 (v1.67/9563) // ssl/https support currently on hardcoded default port 8443 (v1.67/9563)
// make sure YaCy can start (disable ssl/https support if port is used) // make sure YaCy can start (disable ssl/https support if port is used)
if (sb.getConfigBool("server.https", false)) { if (sb.getConfigBool("server.https", false)) {
try {
if (TimeoutRequest.ping("127.0.0.1", 8443, 3000)) { if (TimeoutRequest.ping("127.0.0.1", 8443, 3000)) {
sb.setConfig("server.https", false); sb.setConfig("server.https", false);
ConcurrentLog.info("MIGRATION", "disabled https support (reason: default port 8443 already used)"); ConcurrentLog.info("MIGRATION", "disabled https support (reason: default port 8443 already used)");
} }
} catch (ExecutionException ex) { }
} }
} }
/* /*

@ -68,7 +68,6 @@ import java.util.SortedSet;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -294,15 +293,12 @@ public final class Switchboard extends serverSwitch {
sb = this; sb = this;
// check if port is already occupied // check if port is already occupied
final int port = getConfigInt("port", 8090); final int port = getConfigInt("port", 8090);
try { if (TimeoutRequest.ping(Domains.LOCALHOST, port, 500)) {
if ( TimeoutRequest.ping(Domains.LOCALHOST, port, 500) ) {
throw new RuntimeException( throw new RuntimeException(
"a server is already running on the YaCy port " "a server is already running on the YaCy port "
+ port + port
+ "; possibly another YaCy process has not terminated yet. Please stop YaCy before running a new instance."); + "; possibly another YaCy process has not terminated yet. Please stop YaCy before running a new instance.");
} }
} catch (final ExecutionException e1 ) {
}
MemoryTracker.startSystemProfiling(); MemoryTracker.startSystemProfiling();

@ -559,10 +559,12 @@ public final class yacy {
delete(lockFile); delete(lockFile);
} }
} }
} catch (Throwable ex) { } catch (IOException ex) {
System.err.println("ERROR: config file seems to be corrupt");
System.err.println("ERROR: if problem persists, delete file");
System.err.println(configFile.getAbsolutePath());
ConcurrentLog.logException(ex); ConcurrentLog.logException(ex);
ConcurrentLog.severe("Startup", "cannot read " + configFile.toString() + ", removing old file"); ConcurrentLog.severe("Startup", "cannot read " + configFile.toString() + ", please delete the corrupted file if problem persits");
configFile.delete();
} }
} }
} }

Loading…
Cancel
Save