forked from I2P_Developers/i2p.i2p
- Backup up more Jetty 6 config files before migration
- Try to avoid zip file closed exceptions - Fix jetty.xml, switch from deprecated WebAppDeployer to WebAppProvider
This commit is contained in:
@ -63,6 +63,7 @@ import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
|
||||
import org.eclipse.jetty.servlet.ServletHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.security.Constraint;
|
||||
import org.eclipse.jetty.util.security.Credential;
|
||||
import org.eclipse.jetty.util.security.Credential.MD5;
|
||||
@ -527,6 +528,10 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
|
||||
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=364936
|
||||
// WARN:oejw.WebAppContext:Failed startup of context o.e.j.w.WebAppContext{/,jar:file:/.../webapps/routerconsole.war!/},/.../webapps/routerconsole.war
|
||||
// java.lang.IllegalStateException: zip file closed
|
||||
Resource.setDefaultUseCaches(false);
|
||||
try {
|
||||
// start does a mapContexts()
|
||||
_server.start();
|
||||
|
@ -226,7 +226,7 @@
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.deploy.providers.ContextProvider">
|
||||
<Set name="monitoredDirName">./eepsite/contexts</Set>
|
||||
<Set name="scanInterval">30</Set>
|
||||
<Set name="scanInterval">120</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
@ -245,33 +245,18 @@
|
||||
<!-- Normally only one type of deployer need be used. -->
|
||||
<!-- -->
|
||||
<!-- =========================================================== -->
|
||||
<Call name="addLifeCycle">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.deploy.WebAppDeployer">
|
||||
<Set name="contexts"><Ref id="Contexts"/></Set>
|
||||
<Set name="webAppDir">./eepsite/webapps</Set>
|
||||
<Set name="parentLoaderPriority">false</Set>
|
||||
<!-- set to true if you have uncompiled jsps in your wars -->
|
||||
<Set name="extract">false</Set>
|
||||
<Set name="allowDuplicates">false</Set>
|
||||
<Set name="defaultsDescriptor">./eepsite/etc/webdefault.xml</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
||||
<!-- FIXME Above is deprecated, but this doesn't work
|
||||
java.lang.IllegalStateException: No Method: <Call name="addAppProvider"><New class="org.eclipse.jetty.deploy.providers.WebAppProvider"><Set name="monitoredDirName">./eepsite/webapps</Set><Set name="parentLoaderPriority">false</Set><Set name="extractWars">false</Set><Set name="defaultsDescriptor">./eepsite/etc/webdefault.xml</Set></New></Call> on class org.eclipse.jetty.deploy.DeploymentManager
|
||||
<Ref id="DeploymentManager">
|
||||
<Call id="webappprovider" name="addAppProvider">
|
||||
<New class="org.eclipse.jetty.deploy.providers.WebAppProvider">
|
||||
<Set name="monitoredDirName">./eepsite/webapps</Set>
|
||||
<Set name="parentLoaderPriority">false</Set>
|
||||
<Set name="extractWars">false</Set>
|
||||
<Set name="defaultsDescriptor">./eepsite/etc/webdefault.xml</Set>
|
||||
</New>
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.deploy.providers.WebAppProvider">
|
||||
<Set name="monitoredDirName">./eepsite/webapps</Set>
|
||||
<Set name="parentLoaderPriority">false</Set>
|
||||
<Set name="extractWars">false</Set>
|
||||
<Set name="defaultsDescriptor">./eepsite/etc/webdefault.xml</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
</Ref>
|
||||
-->
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Configure Authentication Realms -->
|
||||
|
@ -12,22 +12,22 @@ import net.i2p.router.RouterContext;
|
||||
|
||||
/**
|
||||
* Migrate the clients.config and jetty.xml files
|
||||
* from Jetty 5 to Jetty 6.
|
||||
* from Jetty 5/6 to Jetty 7.
|
||||
*
|
||||
* 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
|
||||
* Saves $D/jetty.xml to $D/jetty6.xml
|
||||
* Copies $I2P/eepsite-jetty7/jetty.xml to $D/jetty.xml, edited for $D
|
||||
* Copies $I2P/eepsite-jetty7/jetty-ssl.xml to $D/jetty-ssl.xml, edited for $D
|
||||
* Copies $I2P/eepsite-jetty7/jetty-rewrite.xml to $D/jetty-rewrite.xml
|
||||
* Copies $I2P/eepsite-jetty7/context/base-context.xml to $D/jetty.xml, edited for $D
|
||||
* Copies $I2P/eepsite-jetty7/context/cgi-context.xml to $D/jetty.xml, edited for $D
|
||||
* Copies $I2P/eepsite-jetty7/etc/* to $D/etc
|
||||
* Changes main class in clients.config
|
||||
*</pre>
|
||||
* Copies clients.config to clients.config.backup
|
||||
* Saves new clients.config
|
||||
* Copies clients.config to clients.config.jetty6;
|
||||
* Saves new clients.config.
|
||||
*
|
||||
* Does NOT preserve port number, thread counts, etc.
|
||||
*
|
||||
@ -41,12 +41,16 @@ abstract class MigrateJetty {
|
||||
private static final String OLD_CLASS_6 = "org.mortbay.start.Main";
|
||||
private static final String NEW_CLASS = "net.i2p.jetty.JettyStart";
|
||||
private static final String TEST_CLASS = "org.eclipse.jetty.server.Server";
|
||||
private static final String BACKUP = "jetty6.xml";
|
||||
private static final String BACKUP_SUFFIX = ".jetty6";
|
||||
private static final String JETTY_TEMPLATE_DIR = "eepsite-jetty7";
|
||||
private static final String JETTY_TEMPLATE_PKGDIR = "eepsite";
|
||||
private static final String BASE_CONTEXT = "contexts/base-context.xml";
|
||||
private static final String CGI_CONTEXT = "contexts/cgi-context.xml";
|
||||
|
||||
/**
|
||||
* For each entry in apps, if the main class is an old Jetty class,
|
||||
* migrate it to the new Jetty class, and update the Jetty config files.
|
||||
*/
|
||||
public static void migrate(RouterContext ctx, List<ClientAppConfig> apps) {
|
||||
boolean shouldSave = false;
|
||||
for (int i = 0; i < apps.size(); i++) {
|
||||
@ -76,12 +80,9 @@ abstract class MigrateJetty {
|
||||
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);
|
||||
boolean ok = backupFile(xmlFile);
|
||||
if (!ok) {
|
||||
System.err.println("WARNING: Failed to copy XML file " + xmlFile + " to " + backup +
|
||||
System.err.println("WARNING: Failed to backup up XML file " + xmlFile +
|
||||
", cannot migrate " + client);
|
||||
continue;
|
||||
}
|
||||
@ -111,39 +112,36 @@ abstract class MigrateJetty {
|
||||
continue;
|
||||
}
|
||||
// now we're committed, so don't check any more failure codes
|
||||
WorkingDir.migrateJettyXml(baseEep, eepsite, "jetty-ssl.xml", "./eepsite/", newPath);
|
||||
backupAndMigrateFile(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"));
|
||||
// ContextProvider scanner only looks for files ending in .xml so we can
|
||||
// back up to the same directory
|
||||
backupAndMigrateFile(baseEep, eepsite, BASE_CONTEXT, "./eepsite/", newPath);
|
||||
backupAndMigrateFile(baseEep, eepsite, CGI_CONTEXT, "./eepsite/", newPath);
|
||||
backupAndCopyFile(baseEep, eepsite, "jetty-rewrite.xml");
|
||||
(new File(eepsite, "etc")).mkdir();
|
||||
// realm.properties: No change from 6 to 7
|
||||
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);
|
||||
backupAndCopyFile(baseEep, eepsite, "etc/webdefault.xml");
|
||||
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' +
|
||||
"Your old jetty.xml was backed up." + '\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() + ".jetty6");
|
||||
if (backup.exists())
|
||||
backup = new File(cfgFile.getAbsolutePath() + ctx.random().nextInt());
|
||||
boolean ok = WorkingDir.copyFile(cfgFile, backup);
|
||||
boolean ok = backupFile(cfgFile);
|
||||
if (ok) {
|
||||
ClientAppConfig.writeClientAppConfig(ctx, apps);
|
||||
System.err.println("WARNING: Migrated clients config file " + cfgFile +
|
||||
" from Jetty 5/6 " + OLD_CLASS + '/' + OLD_CLASS_6 +
|
||||
" to Jetty 7 " + NEW_CLASS + "\n" +
|
||||
"Your old clients config file was saved as " + backup);
|
||||
" to Jetty 7 " + NEW_CLASS);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -159,4 +157,48 @@ abstract class MigrateJetty {
|
||||
}
|
||||
return _hasLatestJetty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Backup a file
|
||||
* @return success
|
||||
* @since Jetty 7
|
||||
*/
|
||||
private static boolean backupFile(File from) {
|
||||
if (!from.exists())
|
||||
return true;
|
||||
File to = new File(from.getAbsolutePath() + BACKUP_SUFFIX);
|
||||
if (to.exists())
|
||||
to = new File(to.getAbsolutePath() + "." + System.currentTimeMillis());
|
||||
boolean rv = WorkingDir.copyFile(from, to);
|
||||
if (rv)
|
||||
System.err.println("Backed up file " + from + " to " + to);
|
||||
else
|
||||
System.err.println("WARNING: Failed to back up file " + from + " to " + to);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Backup a file and migrate new XML
|
||||
* @return success
|
||||
* @since Jetty 7
|
||||
*/
|
||||
private static boolean backupAndMigrateFile(File templateDir, File toDir, String filename, String fromString, String toString) {
|
||||
File to = new File(toDir, filename);
|
||||
boolean rv = backupFile(to);
|
||||
boolean rv2 = WorkingDir.migrateJettyXml(templateDir, toDir, filename, fromString, toString);
|
||||
return rv && rv2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Backup a file and copy new
|
||||
* @return success
|
||||
* @since Jetty 7
|
||||
*/
|
||||
private static boolean backupAndCopyFile(File templateDir, File toDir, String filename) {
|
||||
File to = new File(toDir, filename);
|
||||
boolean rv = backupFile(to);
|
||||
File from = new File(templateDir, filename);
|
||||
boolean rv2 = WorkingDir.copyFile(from, to);
|
||||
return rv && rv2;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user