+
+
diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java
index 5299dc1781..08ea93bd8c 100644
--- a/router/java/src/net/i2p/router/Router.java
+++ b/router/java/src/net/i2p/router/Router.java
@@ -426,7 +426,11 @@ public class Router implements RouterClock.ClockShiftListener {
foo.putAll(config);
}
- /** this does not use ctx.getConfigDir(), must provide a full path in filename */
+ /**
+ * this does not use ctx.getConfigDir(), must provide a full path in filename
+ *
+ * @param ctx will be null at startup when called from constructor
+ */
private static Properties getConfig(RouterContext ctx, String filename) {
Log log = null;
if (ctx != null) {
@@ -444,10 +448,15 @@ public class Router implements RouterClock.ClockShiftListener {
} else {
if (log != null)
log.warn("Configuration file " + filename + " does not exist");
+ // normal not to exist at first install
+ //else
+ // System.err.println("WARNING: Configuration file " + filename + " does not exist");
}
} catch (Exception ioe) {
if (log != null)
log.error("Error loading the router configuration from " + filename, ioe);
+ else
+ System.err.println("Error loading the router configuration from " + filename + ": " + ioe);
}
return props;
}
@@ -1193,8 +1202,11 @@ public class Router implements RouterClock.ClockShiftListener {
}
fos.write(buf.toString().getBytes("UTF-8"));
} catch (IOException ioe) {
- if (_log.shouldLog(Log.ERROR))
+ // warning, _log will be null when called from constructor
+ if (_log != null)
_log.error("Error saving the config to " + _configFilename, ioe);
+ else
+ System.err.println("Error saving the config to " + _configFilename + ": " + ioe);
return false;
} finally {
if (fos != null) try { fos.close(); } catch (IOException ioe) {}
diff --git a/router/java/src/net/i2p/router/startup/MigrateJetty.java b/router/java/src/net/i2p/router/startup/MigrateJetty.java
index edd1750d08..6a82fff95e 100644
--- a/router/java/src/net/i2p/router/startup/MigrateJetty.java
+++ b/router/java/src/net/i2p/router/startup/MigrateJetty.java
@@ -12,16 +12,17 @@ import net.i2p.router.RouterContext;
/**
* Migrate the clients.config and jetty.xml files
- * from Jetty 5 to Jetty 6
+ * from Jetty 5 to Jetty 6.
*
* For each client for class org.mortbay.jetty.Server:
*
* Let $D be the dir that jetty.xml is in (usually ~/.i2p/eepsite)
* Saves $D/jetty.xml to $D/jetty5.xml
- * Copies $I2P/eepsite/jetty.xml to $D/jetty.xml, edited for $D
- * Copies $I2P/eepsite/context/base-context.xml to $D/jetty.xml, edited for $D
- * Copies $I2P/eepsite/context/cgi-context.xml to $D/jetty.xml, edited for $D
- * Copies $I2P/eepsite/etc/* to $D/etc
+ * Copies $I2P/eepsite-jetty6/jetty.xml to $D/jetty.xml, edited for $D
+ * Copies $I2P/eepsite-jetty6/jetty-ssl.xml to $D/jetty-ssl.xml, edited for $D
+ * Copies $I2P/eepsite-jetty6/context/base-context.xml to $D/jetty.xml, edited for $D
+ * Copies $I2P/eepsite-jetty6/context/cgi-context.xml to $D/jetty.xml, edited for $D
+ * Copies $I2P/eepsite-jetty6/etc/* to $D/etc
* Changes main class in clients.config
*
* Copies clients.config to clients.config.backup
@@ -38,6 +39,7 @@ abstract class MigrateJetty {
private static final String OLD_CLASS = "org.mortbay.jetty.Server";
private static final String NEW_CLASS = "org.mortbay.start.Main";
private static final String BACKUP = "jetty5.xml";
+ private static final String JETTY6_TEMPLATE_DIR = "eepsite-jetty6";
private static final String BASE_CONTEXT = "contexts/base-context.xml";
private static final String CGI_CONTEXT = "contexts/cgi-context.xml";
@@ -47,61 +49,52 @@ abstract class MigrateJetty {
ClientAppConfig app = apps.get(i);
if (!app.className.equals(OLD_CLASS))
continue;
+ String client = "client application " + i + " [" + app.clientName +
+ "] from Jetty 5 " + OLD_CLASS +
+ " to Jetty 6 " + NEW_CLASS;
if (!hasJetty6()) {
- System.err.println("WARNING: Jetty 6 unavailable, cannot migrate client " + i +
- " from Jetty 5 class " + OLD_CLASS +
- " to Jetty 6 class " + NEW_CLASS);
+ System.err.println("WARNING: Jetty 6 unavailable, cannot migrate " + client);
continue;
}
String xml = app.args;
if (xml == null)
continue;
File xmlFile = new File(xml);
- if ((!xmlFile.exists()) || (!xmlFile.isAbsolute())) {
+ if (!xmlFile.isAbsolute())
+ xmlFile = new File(ctx.getAppDir(), xml);
+ if (!xmlFile.exists()) {
System.err.println("WARNING: XML file " + xmlFile +
- " not found, cannot migrate client " + i +
- " from Jetty 5 class " + OLD_CLASS +
- " to Jetty 6 class " + NEW_CLASS);
+ " not found, cannot migrate " + client);
continue;
}
File eepsite = xmlFile.getParentFile();
File backup = new File(eepsite, BACKUP);
- if (backup.exists()) {
- System.err.println("WARNING: Backup XML file " + backup + " already exists" +
- ", cannot migrate client " + i +
- " from Jetty 5 class " + OLD_CLASS +
- " to Jetty 6 class " + NEW_CLASS);
- continue;
- }
+ if (backup.exists())
+ backup = new File(eepsite, BACKUP + ctx.random().nextInt());
boolean ok = WorkingDir.copyFile(xmlFile, backup);
if (!ok) {
System.err.println("WARNING: Failed to copy XML file " + xmlFile + " to " + backup +
- ", cannot migrate client " + i +
- " from Jetty 5 class " + OLD_CLASS +
- " to Jetty 6 class " + NEW_CLASS);
+ ", cannot migrate " + client);
continue;
}
- File baseEep = new File(ctx.getBaseDir(), "eepsite");
+ File baseEep = new File(ctx.getBaseDir(), JETTY6_TEMPLATE_DIR);
// jetty.xml existed before in jetty 5 version, so check this new file
// and if it doesn't exist we can't continue
File baseContext = new File(baseEep, BASE_CONTEXT);
if (!baseContext.exists()) {
System.err.println("WARNING: Cannot find new XML file template " + baseContext +
- ", cannot migrate client " + i +
- " from Jetty 5 class " + OLD_CLASS +
- " to Jetty 6 class " + NEW_CLASS);
+ ", cannot migrate " + client);
continue;
}
String newPath = eepsite.getAbsolutePath() + File.separatorChar;
ok = WorkingDir.migrateJettyXml(baseEep, eepsite, "jetty.xml", "./eepsite/", newPath);
if (!ok) {
System.err.println("WARNING: Failed to modify XML file " + xmlFile +
- ", cannot migrate client " + i +
- " from Jetty 5 class " + OLD_CLASS +
- " to Jetty 6 class " + NEW_CLASS);
+ ", cannot migrate " + client);
continue;
}
// now we're committed, so don't check any more failure codes
+ WorkingDir.migrateJettyXml(baseEep, eepsite, "jetty-ssl.xml", "./eepsite/", newPath);
(new File(eepsite, "contexts")).mkdir();
WorkingDir.migrateJettyXml(baseEep, eepsite, BASE_CONTEXT, "./eepsite/", newPath);
WorkingDir.migrateJettyXml(baseEep, eepsite, CGI_CONTEXT, "./eepsite/", newPath);
@@ -114,24 +107,25 @@ abstract class MigrateJetty {
WorkingDir.copyFile(new File(baseEep, "etc/webdefault.xml"), to);
app.className = NEW_CLASS;
shouldSave = true;
- System.err.println("WARNING: Migrated client " + i + " from Jetty 5 class " + OLD_CLASS +
- " to Jetty 6 class " + NEW_CLASS + ".\n" +
- "Check the following files in " + baseEep +
+ System.err.println("WARNING: Migrated " + client + '\n' +
+ "Check the following files in " + eepsite +
": jetty.xml, " + BASE_CONTEXT + ", and " + CGI_CONTEXT + "\n" +
- "Your old jetty.xml was saved as jetty5.xml\n" +
+ "Your old jetty.xml was saved as " + backup + '\n' +
"If you modified your jetty.xml to change ports, thread limits, etc, you MUST\n" +
"edit it to change them again. Your port was reset to 7658.");
}
if (shouldSave) {
File cfgFile = ClientAppConfig.configFile(ctx);
File backup = new File(cfgFile.getAbsolutePath() + ".jetty5");
+ if (backup.exists())
+ backup = new File(cfgFile.getAbsolutePath() + ctx.random().nextInt());
boolean ok = WorkingDir.copyFile(cfgFile, backup);
if (ok) {
ClientAppConfig.writeClientAppConfig(ctx, apps);
System.err.println("WARNING: Migrated clients config file " + cfgFile +
- " from Jetty 5 class " + OLD_CLASS +
- " to Jetty 6 class " + NEW_CLASS + "\n" +
- "Your old clients config file was saved as " + cfgFile + ".jetty5");
+ " from Jetty 5 " + OLD_CLASS +
+ " to Jetty 6 " + NEW_CLASS + "\n" +
+ "Your old clients config file was saved as " + backup);
}
}
}
diff --git a/router/java/src/net/i2p/router/startup/WorkingDir.java b/router/java/src/net/i2p/router/startup/WorkingDir.java
index 888262302e..45e6bf5e33 100644
--- a/router/java/src/net/i2p/router/startup/WorkingDir.java
+++ b/router/java/src/net/i2p/router/startup/WorkingDir.java
@@ -148,7 +148,7 @@ public class WorkingDir {
boolean success = migrate(MIGRATE_BASE, oldDirf, dirf);
// this one must be after MIGRATE_BASE
File oldEep = new File(oldDirf, "eepsite");
- File newEep = new File(oldDirf, "eepsite");
+ File newEep = new File(dirf, "eepsite");
String newPath = newEep.getAbsolutePath() + File.separatorChar;
success &= migrateJettyXml(oldEep, newEep, "jetty.xml", "./eepsite/", newPath);
success &= migrateJettyXml(oldEep, newEep, "jetty-ssl.xml", "./eepsite/", newPath);
@@ -245,11 +245,11 @@ public class WorkingDir {
}
out.println(s);
}
- System.err.println("Copied clients.config with modifications");
+ System.err.println("Copied " + oldFile + " with modifications");
return true;
} catch (IOException ioe) {
if (in != null) {
- System.err.println("FAILED copy clients.config");
+ System.err.println("FAILED copy " + oldFile + ": " + ioe);
return false;
}
return false;
@@ -280,11 +280,11 @@ public class WorkingDir {
out.println(s);
}
out.println("");
- System.err.println("Copied " + filename + " with modifications");
+ System.err.println("Copied " + oldFile + " with modifications");
return true;
} catch (IOException ioe) {
if (in != null) {
- System.err.println("FAILED copy " + filename);
+ System.err.println("FAILED copy " + oldFile + ": " + ioe);
return false;
}
return false;
@@ -357,7 +357,7 @@ public class WorkingDir {
System.err.println("Copied " + src.getPath());
} catch (IOException ioe) {
- System.err.println("FAILED copy " + src.getPath());
+ System.err.println("FAILED copy " + src.getPath() + ": " + ioe);
rv = false;
} finally {
if (in != null) try { in.close(); } catch (IOException ioe) {}