Changeset bb8183d


Ignore:
Timestamp:
Apr 8, 2013 3:29:02 PM (7 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
2557a0b
Parents:
9478a84
Message:
  • 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?
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java

    r9478a84 rbb8183d  
    6464import org.eclipse.jetty.servlet.ServletHolder;
    6565import org.eclipse.jetty.webapp.WebAppContext;
     66import org.eclipse.jetty.util.resource.Resource;
    6667import org.eclipse.jetty.util.security.Constraint;
    6768import org.eclipse.jetty.util.security.Credential;
     
    528529        }
    529530
     531        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=364936
     532        // WARN:oejw.WebAppContext:Failed startup of context o.e.j.w.WebAppContext{/,jar:file:/.../webapps/routerconsole.war!/},/.../webapps/routerconsole.war
     533        // java.lang.IllegalStateException: zip file closed
     534        Resource.setDefaultUseCaches(false);
    530535        try {
    531536            // start does a mapContexts()
  • installer/resources/eepsite/jetty.xml

    r9478a84 rbb8183d  
    227227          <New class="org.eclipse.jetty.deploy.providers.ContextProvider">
    228228            <Set name="monitoredDirName">./eepsite/contexts</Set>
    229             <Set name="scanInterval">30</Set>
     229            <Set name="scanInterval">120</Set>
    230230          </New>
    231231        </Arg>
     
    246246    <!--                                                             -->
    247247    <!-- =========================================================== -->
    248     <Call name="addLifeCycle">
    249       <Arg>
    250         <New class="org.eclipse.jetty.deploy.WebAppDeployer">
    251           <Set name="contexts"><Ref id="Contexts"/></Set>
    252           <Set name="webAppDir">./eepsite/webapps</Set>
    253           <Set name="parentLoaderPriority">false</Set>
    254           <!-- set to true if you have uncompiled jsps in your wars -->
    255           <Set name="extract">false</Set>
    256           <Set name="allowDuplicates">false</Set>
    257           <Set name="defaultsDescriptor">./eepsite/etc/webdefault.xml</Set>
    258         </New>
    259       </Arg>
    260     </Call>
    261 
    262 <!-- FIXME Above is deprecated, but this doesn't work
    263      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
    264248    <Ref id="DeploymentManager">
    265249      <Call id="webappprovider" name="addAppProvider">
    266         <New class="org.eclipse.jetty.deploy.providers.WebAppProvider">
    267           <Set name="monitoredDirName">./eepsite/webapps</Set>
    268           <Set name="parentLoaderPriority">false</Set>
    269           <Set name="extractWars">false</Set>
    270           <Set name="defaultsDescriptor">./eepsite/etc/webdefault.xml</Set>
    271         </New>
     250        <Arg>
     251          <New class="org.eclipse.jetty.deploy.providers.WebAppProvider">
     252            <Set name="monitoredDirName">./eepsite/webapps</Set>
     253            <Set name="parentLoaderPriority">false</Set>
     254            <Set name="extractWars">false</Set>
     255            <Set name="defaultsDescriptor">./eepsite/etc/webdefault.xml</Set>
     256          </New>
     257        </Arg>
    272258      </Call>
    273259    </Ref>
    274 -->
    275260
    276261    <!-- =========================================================== -->
  • router/java/src/net/i2p/router/startup/MigrateJetty.java

    r9478a84 rbb8183d  
    1313/**
    1414 *  Migrate the clients.config and jetty.xml files
    15  *  from Jetty 5 to Jetty 6.
     15 *  from Jetty 5/6 to Jetty 7.
    1616 *
    1717 *  For each client for class org.mortbay.jetty.Server:
    1818 *<pre>
    1919 *  Let $D be the dir that jetty.xml is in (usually ~/.i2p/eepsite)
    20  *  Saves $D/jetty.xml to $D/jetty5.xml
    21  *  Copies $I2P/eepsite-jetty6/jetty.xml to $D/jetty.xml, edited for $D
    22  *  Copies $I2P/eepsite-jetty6/jetty-ssl.xml to $D/jetty-ssl.xml, edited for $D
    23  *  Copies $I2P/eepsite-jetty6/jetty-rewrite.xml to $D/jetty-rewrite.xml
    24  *  Copies $I2P/eepsite-jetty6/context/base-context.xml to $D/jetty.xml, edited for $D
    25  *  Copies $I2P/eepsite-jetty6/context/cgi-context.xml to $D/jetty.xml, edited for $D
    26  *  Copies $I2P/eepsite-jetty6/etc/* to $D/etc
     20 *  Saves $D/jetty.xml to $D/jetty6.xml
     21 *  Copies $I2P/eepsite-jetty7/jetty.xml to $D/jetty.xml, edited for $D
     22 *  Copies $I2P/eepsite-jetty7/jetty-ssl.xml to $D/jetty-ssl.xml, edited for $D
     23 *  Copies $I2P/eepsite-jetty7/jetty-rewrite.xml to $D/jetty-rewrite.xml
     24 *  Copies $I2P/eepsite-jetty7/context/base-context.xml to $D/jetty.xml, edited for $D
     25 *  Copies $I2P/eepsite-jetty7/context/cgi-context.xml to $D/jetty.xml, edited for $D
     26 *  Copies $I2P/eepsite-jetty7/etc/* to $D/etc
    2727 *  Changes main class in clients.config
    2828 *</pre>
    29  *  Copies clients.config to clients.config.backup
    30  *  Saves new clients.config
     29 *  Copies clients.config to clients.config.jetty6;
     30 *  Saves new clients.config.
    3131 *
    3232 *  Does NOT preserve port number, thread counts, etc.
     
    4242    private static final String NEW_CLASS = "net.i2p.jetty.JettyStart";
    4343    private static final String TEST_CLASS = "org.eclipse.jetty.server.Server";
    44     private static final String BACKUP = "jetty6.xml";
     44    private static final String BACKUP_SUFFIX = ".jetty6";
    4545    private static final String JETTY_TEMPLATE_DIR = "eepsite-jetty7";
    4646    private static final String JETTY_TEMPLATE_PKGDIR = "eepsite";
     
    4848    private static final String CGI_CONTEXT = "contexts/cgi-context.xml";
    4949   
     50    /**
     51     *  For each entry in apps, if the main class is an old Jetty class,
     52     *  migrate it to the new Jetty class, and update the Jetty config files.
     53     */
    5054    public static void migrate(RouterContext ctx, List<ClientAppConfig> apps) {
    5155        boolean shouldSave = false;
     
    7781            }
    7882            File eepsite = xmlFile.getParentFile();
    79             File backup = new File(eepsite, BACKUP);
    80             if (backup.exists())
    81                 backup = new File(eepsite, BACKUP + ctx.random().nextInt());
    82             boolean ok = WorkingDir.copyFile(xmlFile, backup);
     83            boolean ok = backupFile(xmlFile);
    8384            if (!ok) {
    84                 System.err.println("WARNING: Failed to copy XML file " + xmlFile + " to " + backup +
     85                System.err.println("WARNING: Failed to backup up XML file " + xmlFile +
    8586                               ", cannot migrate " + client);
    8687                continue;
     
    112113            }
    113114            // now we're committed, so don't check any more failure codes
    114             WorkingDir.migrateJettyXml(baseEep, eepsite, "jetty-ssl.xml", "./eepsite/", newPath);
     115            backupAndMigrateFile(baseEep, eepsite, "jetty-ssl.xml", "./eepsite/", newPath);
    115116            (new File(eepsite, "contexts")).mkdir();
    116             WorkingDir.migrateJettyXml(baseEep, eepsite, BASE_CONTEXT, "./eepsite/", newPath);
    117             WorkingDir.migrateJettyXml(baseEep, eepsite, CGI_CONTEXT, "./eepsite/", newPath);
    118             WorkingDir.copyFile(new File(baseEep, "jetty-rewrite.xml"), new File(eepsite, "jetty-rewrite.xml"));
     117            // ContextProvider scanner only looks for files ending in .xml so we can
     118            // back up to the same directory
     119            backupAndMigrateFile(baseEep, eepsite, BASE_CONTEXT, "./eepsite/", newPath);
     120            backupAndMigrateFile(baseEep, eepsite, CGI_CONTEXT, "./eepsite/", newPath);
     121            backupAndCopyFile(baseEep, eepsite, "jetty-rewrite.xml");
    119122            (new File(eepsite, "etc")).mkdir();
     123            // realm.properties: No change from 6 to 7
    120124            File to = new File(eepsite, "etc/realm.properties");
    121125            if (!to.exists())
    122126                WorkingDir.copyFile(new File(baseEep, "etc/realm.properties"), to);
    123             to = new File(eepsite, "etc/webdefault.xml");
    124             if (!to.exists())
    125                 WorkingDir.copyFile(new File(baseEep, "etc/webdefault.xml"), to);
     127            backupAndCopyFile(baseEep, eepsite, "etc/webdefault.xml");
    126128            app.className = NEW_CLASS;
    127129            shouldSave = true;
     
    129131                               "Check the following files in " + eepsite +
    130132                               ": jetty.xml, " + BASE_CONTEXT + ", and " + CGI_CONTEXT + "\n" +
    131                                "Your old jetty.xml was saved as " + backup + '\n' +
     133                               "Your old jetty.xml was backed up." + '\n' +
    132134                               "If you modified your jetty.xml to change ports, thread limits, etc, you MUST\n" +
    133135                               "edit it to change them again. Your port was reset to 7658.");
     
    135137        if (shouldSave) {
    136138            File cfgFile = ClientAppConfig.configFile(ctx);
    137             File backup = new File(cfgFile.getAbsolutePath() + ".jetty6");
    138             if (backup.exists())
    139                 backup = new File(cfgFile.getAbsolutePath() + ctx.random().nextInt());
    140             boolean ok = WorkingDir.copyFile(cfgFile, backup);
     139            boolean ok = backupFile(cfgFile);
    141140            if (ok) {
    142141                ClientAppConfig.writeClientAppConfig(ctx, apps);
    143142                System.err.println("WARNING: Migrated clients config file " + cfgFile +
    144143                               " from Jetty 5/6 " + OLD_CLASS + '/' + OLD_CLASS_6 +
    145                                " to Jetty 7 " + NEW_CLASS + "\n" +
    146                                "Your old clients config file was saved as " + backup);
     144                               " to Jetty 7 " + NEW_CLASS);
    147145            }
    148146        }
     
    160158        return _hasLatestJetty;
    161159    }
     160
     161    /**
     162     *  Backup a file
     163     *  @return success
     164     *  @since Jetty 7
     165     */
     166    private static boolean backupFile(File from) {
     167        if (!from.exists())
     168            return true;
     169        File to = new File(from.getAbsolutePath() + BACKUP_SUFFIX);
     170        if (to.exists())
     171            to = new File(to.getAbsolutePath() + "." + System.currentTimeMillis());
     172        boolean rv = WorkingDir.copyFile(from, to);
     173        if (rv)
     174            System.err.println("Backed up file " + from + " to " + to);
     175        else
     176            System.err.println("WARNING: Failed to back up file " + from + " to " + to);
     177        return rv;
     178    }
     179
     180    /**
     181     *  Backup a file and migrate new XML
     182     *  @return success
     183     *  @since Jetty 7
     184     */
     185    private static boolean backupAndMigrateFile(File templateDir, File toDir, String filename, String fromString, String toString) {
     186        File to = new File(toDir, filename);
     187        boolean rv = backupFile(to);
     188        boolean rv2 = WorkingDir.migrateJettyXml(templateDir, toDir, filename, fromString, toString);
     189        return rv && rv2;
     190    }
     191
     192    /**
     193     *  Backup a file and copy new
     194     *  @return success
     195     *  @since Jetty 7
     196     */
     197    private static boolean backupAndCopyFile(File templateDir, File toDir, String filename) {
     198        File to = new File(toDir, filename);
     199        boolean rv = backupFile(to);
     200        File from = new File(templateDir, filename);
     201        boolean rv2 = WorkingDir.copyFile(from, to);
     202        return rv && rv2;
     203    }
    162204}
Note: See TracChangeset for help on using the changeset viewer.