forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p.zzz.jetty6' (head b2ad0d72311d5ec26270cfcbbc79d128b268869b)
to branch 'i2p.i2p' (head b05b73d4740740f306a665e4b354d412eab2f328)
This commit is contained in:
@ -1420,11 +1420,13 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
// and we will die with NCDFE.
|
||||
// Ideally, do not use I2P classes at all, new or not.
|
||||
try {
|
||||
// TODO move deleteListedFiles() here after a few releases
|
||||
if (ok)
|
||||
if (ok) {
|
||||
// We do this here so we may delete old jars before we restart
|
||||
deleteListedFiles();
|
||||
System.out.println("INFO: Update installed");
|
||||
else
|
||||
} else {
|
||||
System.out.println("ERROR: Update failed!");
|
||||
}
|
||||
if (!ok) {
|
||||
// we can't leave the file in place or we'll continually restart, so rename it
|
||||
File bad = new File(_context.getRouterDir(), "BAD-" + UPDATE_FILE);
|
||||
@ -1455,8 +1457,10 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
System.exit(EXIT_HARD_RESTART);
|
||||
} else {
|
||||
deleteJbigiFiles();
|
||||
// Here so it may be used in the 0.8.12 update
|
||||
// TODO move up in a few releases so it is only run after an update
|
||||
// It was here starting in 0.8.12 so it could be used the very first time
|
||||
// Now moved up so it is usually run only after an update
|
||||
// But the first time before jetty 6 it will run here...
|
||||
// Here we can't remove jars
|
||||
deleteListedFiles();
|
||||
}
|
||||
}
|
||||
|
@ -131,14 +131,18 @@ public class ClientAppConfig {
|
||||
|
||||
/*
|
||||
* Go through the properties, and return a List of ClientAppConfig structures
|
||||
* This is for the router.
|
||||
*/
|
||||
public static List<ClientAppConfig> getClientApps(RouterContext ctx) {
|
||||
Properties clientApps = getClientAppProps(ctx);
|
||||
return getClientApps(clientApps);
|
||||
List<ClientAppConfig> rv = getClientApps(clientApps);
|
||||
MigrateJetty.migrate(ctx, rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* Go through the properties, and return a List of ClientAppConfig structures
|
||||
* This is for plugins.
|
||||
*
|
||||
* @since 0.7.12
|
||||
*/
|
||||
@ -190,14 +194,14 @@ public class ClientAppConfig {
|
||||
}
|
||||
|
||||
/** classpath and stopargs not supported */
|
||||
public static void writeClientAppConfig(RouterContext ctx, List apps) {
|
||||
public static void writeClientAppConfig(RouterContext ctx, List<ClientAppConfig> apps) {
|
||||
File cfgFile = configFile(ctx);
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new SecureFileOutputStream(cfgFile);
|
||||
StringBuilder buf = new StringBuilder(2048);
|
||||
for(int i = 0; i < apps.size(); i++) {
|
||||
ClientAppConfig app = (ClientAppConfig) apps.get(i);
|
||||
ClientAppConfig app = apps.get(i);
|
||||
buf.append(PREFIX).append(i).append(".main=").append(app.className).append("\n");
|
||||
buf.append(PREFIX).append(i).append(".name=").append(app.clientName).append("\n");
|
||||
if (app.args != null)
|
||||
|
159
router/java/src/net/i2p/router/startup/MigrateJetty.java
Normal file
159
router/java/src/net/i2p/router/startup/MigrateJetty.java
Normal file
@ -0,0 +1,159 @@
|
||||
package net.i2p.router.startup;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import net.i2p.router.RouterContext;
|
||||
|
||||
/**
|
||||
* Migrate the clients.config and jetty.xml files
|
||||
* from Jetty 5 to Jetty 6.
|
||||
*
|
||||
* For each client for class org.mortbay.jetty.Server:
|
||||
*<pre>
|
||||
* Let $D be the dir that jetty.xml is in (usually ~/.i2p/eepsite)
|
||||
* Saves $D/jetty.xml to $D/jetty5.xml
|
||||
* 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/jetty-rewrite.xml to $D/jetty-rewrite.xml
|
||||
* 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
|
||||
*</pre>
|
||||
* Copies clients.config to clients.config.backup
|
||||
* Saves new clients.config
|
||||
*
|
||||
* Does NOT preserve port number, thread counts, etc.
|
||||
*
|
||||
* @since Jetty 6
|
||||
*/
|
||||
abstract class MigrateJetty {
|
||||
private static boolean _wasChecked;
|
||||
private static boolean _hasJetty6;
|
||||
|
||||
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 JETTY6_TEMPLATE_PKGDIR = "eepsite";
|
||||
private static final String BASE_CONTEXT = "contexts/base-context.xml";
|
||||
private static final String CGI_CONTEXT = "contexts/cgi-context.xml";
|
||||
|
||||
public static void migrate(RouterContext ctx, List<ClientAppConfig> apps) {
|
||||
boolean shouldSave = false;
|
||||
for (int i = 0; i < apps.size(); i++) {
|
||||
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);
|
||||
continue;
|
||||
}
|
||||
if (app.args == null)
|
||||
continue;
|
||||
// remove quotes
|
||||
String args[] = LoadClientAppsJob.parseArgs(app.args);
|
||||
if (args.length == 0)
|
||||
continue;
|
||||
String xml = args[0];
|
||||
File xmlFile = new File(xml);
|
||||
if (!xmlFile.isAbsolute())
|
||||
xmlFile = new File(ctx.getAppDir(), xml);
|
||||
if (!xmlFile.exists()) {
|
||||
System.err.println("WARNING: XML file " + xmlFile +
|
||||
" not found, cannot migrate " + client);
|
||||
continue;
|
||||
}
|
||||
File eepsite = xmlFile.getParentFile();
|
||||
File backup = new File(eepsite, BACKUP);
|
||||
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);
|
||||
continue;
|
||||
}
|
||||
File baseEep = new File(ctx.getBaseDir(), JETTY6_TEMPLATE_DIR);
|
||||
// in packages, or perhaps on an uninstall/reinstall, the files are in eepsite/
|
||||
if (!baseEep.exists())
|
||||
baseEep = new File(ctx.getBaseDir(), JETTY6_TEMPLATE_PKGDIR);
|
||||
if (baseEep.equals(eepsite)) {
|
||||
// non-split directory yet not an upgrade? shouldn't happen
|
||||
System.err.println("Eepsite in non-split directory " + eepsite +
|
||||
", cannot migrate " + client);
|
||||
continue;
|
||||
}
|
||||
// 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);
|
||||
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);
|
||||
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);
|
||||
WorkingDir.copyFile(new File(baseEep, "jetty-rewrite.xml"), new File(eepsite, "jetty-rewrite.xml"));
|
||||
(new File(eepsite, "etc")).mkdir();
|
||||
File to = new File(eepsite, "etc/realm.properties");
|
||||
if (!to.exists())
|
||||
WorkingDir.copyFile(new File(baseEep, "etc/realm.properties"), to);
|
||||
to = new File(eepsite, "etc/webdefault.xml");
|
||||
if (!to.exists())
|
||||
WorkingDir.copyFile(new File(baseEep, "etc/webdefault.xml"), to);
|
||||
app.className = NEW_CLASS;
|
||||
shouldSave = true;
|
||||
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 " + 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 " + OLD_CLASS +
|
||||
" to Jetty 6 " + NEW_CLASS + "\n" +
|
||||
"Your old clients config file was saved as " + backup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasJetty6() {
|
||||
if (!_wasChecked) {
|
||||
try {
|
||||
LoadClientAppsJob.testClient(NEW_CLASS, null);
|
||||
_hasJetty6 = true;
|
||||
} catch (ClassNotFoundException cnfe) {}
|
||||
_wasChecked = true;
|
||||
}
|
||||
return _hasJetty6;
|
||||
}
|
||||
}
|
@ -163,7 +163,13 @@ public class WorkingDir {
|
||||
System.err.println("Setting up new user directory " + rv);
|
||||
boolean success = migrate(MIGRATE_BASE, oldDirf, dirf);
|
||||
// this one must be after MIGRATE_BASE
|
||||
success &= migrateJettyXml(oldDirf, dirf);
|
||||
File oldEep = 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);
|
||||
success &= migrateJettyXml(oldEep, newEep, "contexts/base-context.xml", "./eepsite/", newPath);
|
||||
success &= migrateJettyXml(oldEep, newEep, "contexts/cgi-context.xml", "./eepsite/", newPath);
|
||||
success &= migrateClientsConfig(oldDirf, dirf);
|
||||
// for later news.xml updates (we don't copy initialNews.xml over anymore)
|
||||
success &= (new SecureDirectory(dirf, "docs")).mkdir();
|
||||
@ -298,11 +304,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;
|
||||
@ -317,11 +323,9 @@ public class WorkingDir {
|
||||
* It was already copied over once in migrate(), throw that out and
|
||||
* do it again with modifications.
|
||||
*/
|
||||
private static boolean migrateJettyXml(File olddir, File todir) {
|
||||
File eepsite1 = new File(olddir, "eepsite");
|
||||
File oldFile = new File(eepsite1, "jetty.xml");
|
||||
File eepsite2 = new File(todir, "eepsite");
|
||||
File newFile = new File(eepsite2, "jetty.xml");
|
||||
static boolean migrateJettyXml(File olddir, File todir, String filename, String oldString, String newString) {
|
||||
File oldFile = new File(olddir, filename);
|
||||
File newFile = new File(todir, filename);
|
||||
FileInputStream in = null;
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
@ -329,17 +333,17 @@ public class WorkingDir {
|
||||
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(newFile), "UTF-8")));
|
||||
String s = null;
|
||||
while ((s = DataHelper.readLine(in)) != null) {
|
||||
if (s.indexOf("./eepsite/") >= 0) {
|
||||
s = s.replace("./eepsite/", todir.getAbsolutePath() + File.separatorChar + "eepsite" + File.separatorChar);
|
||||
if (s.indexOf(oldString) >= 0) {
|
||||
s = s.replace(oldString, newString);
|
||||
}
|
||||
out.println(s);
|
||||
}
|
||||
out.println("<!-- Modified by I2P User dir migration script -->");
|
||||
System.err.println("Copied jetty.xml with modifications");
|
||||
System.err.println("Copied " + oldFile + " with modifications");
|
||||
return true;
|
||||
} catch (IOException ioe) {
|
||||
if (in != null) {
|
||||
System.err.println("FAILED copy jetty.xml");
|
||||
System.err.println("FAILED copy " + oldFile + ": " + ioe);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
@ -395,7 +399,7 @@ public class WorkingDir {
|
||||
* @param dst not a directory, will be overwritten if existing, will be mode 600
|
||||
* @return true if it was copied successfully
|
||||
*/
|
||||
private static boolean copyFile(File src, File dst) {
|
||||
static boolean copyFile(File src, File dst) {
|
||||
if (!src.exists()) return false;
|
||||
boolean rv = true;
|
||||
|
||||
@ -412,7 +416,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) {}
|
||||
|
Reference in New Issue
Block a user