Changeset b5f97d0


Ignore:
Timestamp:
Dec 31, 2011 2:38:37 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
33b25b57, 84e4558
Parents:
beb6d1f4
Message:
  • Fix jetty.xml copy bug
  • Fix NPE logging error when Router.saveConfig() fails early
  • Log readConfig() and saveConfig() errors to wrapper log if router log not yet available
  • Handle non-split configuration in MigrateJetty?
  • Better logging of migration errors
  • Handle existing backup files during migration better
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • build.xml

    rbeb6d1f4 rb5f97d0  
    938938            <fileset dir="build" includes="jasper*.jar javax*.jar jetty*.jar jsp*.jar org.mortbay.jetty.jar" />
    939939        </copy>
    940         <copy todir="pkg-temp/eepsite" >
     940        <!--  We have to package the new eepsite files for MigrateJetty.java, but we
     941              can't overwrite an existing eepsite dir in a non-split configuration.
     942          -->
     943        <copy todir="pkg-temp/eepsite-jetty6" >
    941944            <fileset dir="installer/resources/eepsite" includes="jetty.xml jetty-ssl.xml contexts/* etc/*" />
    942945        </copy>
  • router/java/src/net/i2p/router/Router.java

    rbeb6d1f4 rb5f97d0  
    427427    }
    428428   
    429     /** this does not use ctx.getConfigDir(), must provide a full path in filename */
     429    /**
     430     *  this does not use ctx.getConfigDir(), must provide a full path in filename
     431     *
     432     *  @param ctx will be null at startup when called from constructor
     433     */
    430434    private static Properties getConfig(RouterContext ctx, String filename) {
    431435        Log log = null;
     
    445449                if (log != null)
    446450                    log.warn("Configuration file " + filename + " does not exist");
     451                // normal not to exist at first install
     452                //else
     453                //    System.err.println("WARNING: Configuration file " + filename + " does not exist");
    447454            }
    448455        } catch (Exception ioe) {
    449456            if (log != null)
    450457                log.error("Error loading the router configuration from " + filename, ioe);
     458            else
     459                System.err.println("Error loading the router configuration from " + filename + ": " + ioe);
    451460        }
    452461        return props;
     
    11941203            fos.write(buf.toString().getBytes("UTF-8"));
    11951204        } catch (IOException ioe) {
    1196             if (_log.shouldLog(Log.ERROR))
     1205            // warning, _log will be null when called from constructor
     1206            if (_log != null)
    11971207                _log.error("Error saving the config to " + _configFilename, ioe);
     1208            else
     1209                System.err.println("Error saving the config to " + _configFilename + ": " + ioe);
    11981210            return false;
    11991211        } finally {
  • router/java/src/net/i2p/router/startup/MigrateJetty.java

    rbeb6d1f4 rb5f97d0  
    1313/**
    1414 *  Migrate the clients.config and jetty.xml files
    15  *  from Jetty 5 to Jetty 6
     15 *  from Jetty 5 to Jetty 6.
    1616 *
    1717 *  For each client for class org.mortbay.jetty.Server:
     
    1919 *  Let $D be the dir that jetty.xml is in (usually ~/.i2p/eepsite)
    2020 *  Saves $D/jetty.xml to $D/jetty5.xml
    21  *  Copies $I2P/eepsite/jetty.xml to $D/jetty.xml, edited for $D
    22  *  Copies $I2P/eepsite/context/base-context.xml to $D/jetty.xml, edited for $D
    23  *  Copies $I2P/eepsite/context/cgi-context.xml to $D/jetty.xml, edited for $D
    24  *  Copies $I2P/eepsite/etc/* to $D/etc
     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/context/base-context.xml to $D/jetty.xml, edited for $D
     24 *  Copies $I2P/eepsite-jetty6/context/cgi-context.xml to $D/jetty.xml, edited for $D
     25 *  Copies $I2P/eepsite-jetty6/etc/* to $D/etc
    2526 *  Changes main class in clients.config
    2627 *</pre>
     
    3940    private static final String NEW_CLASS = "org.mortbay.start.Main";
    4041    private static final String BACKUP = "jetty5.xml";
     42    private static final String JETTY6_TEMPLATE_DIR = "eepsite-jetty6";
    4143    private static final String BASE_CONTEXT = "contexts/base-context.xml";
    4244    private static final String CGI_CONTEXT = "contexts/cgi-context.xml";
     
    4850            if (!app.className.equals(OLD_CLASS))
    4951                continue;
     52            String client = "client application " + i + " [" + app.clientName +
     53                            "] from Jetty 5 " + OLD_CLASS +
     54                            " to Jetty 6 " + NEW_CLASS;
    5055            if (!hasJetty6()) {
    51                 System.err.println("WARNING: Jetty 6 unavailable, cannot migrate client " + i +
    52                                " from Jetty 5 class " + OLD_CLASS +
    53                                " to Jetty 6 class " + NEW_CLASS);
     56                System.err.println("WARNING: Jetty 6 unavailable, cannot migrate " + client);
    5457                continue;
    5558            }
     
    5861                continue;
    5962            File xmlFile = new File(xml);
    60             if ((!xmlFile.exists()) || (!xmlFile.isAbsolute())) {
     63            if (!xmlFile.isAbsolute())
     64                xmlFile = new File(ctx.getAppDir(), xml);
     65            if (!xmlFile.exists()) {
    6166                System.err.println("WARNING: XML file " + xmlFile +
    62                                " not found, cannot migrate client " + i +
    63                                " from Jetty 5 class " + OLD_CLASS +
    64                                " to Jetty 6 class " + NEW_CLASS);
     67                               " not found, cannot migrate " + client);
    6568                continue;
    6669            }
    6770            File eepsite = xmlFile.getParentFile();
    6871            File backup = new File(eepsite, BACKUP);
    69             if (backup.exists()) {
    70                 System.err.println("WARNING: Backup XML file " + backup + " already exists" +
    71                                ", cannot migrate client " + i +
    72                                " from Jetty 5 class " + OLD_CLASS +
    73                                " to Jetty 6 class " + NEW_CLASS);
    74                 continue;
    75             }
     72            if (backup.exists())
     73                backup = new File(eepsite, BACKUP + ctx.random().nextInt());
    7674            boolean ok = WorkingDir.copyFile(xmlFile, backup);
    7775            if (!ok) {
    7876                System.err.println("WARNING: Failed to copy XML file " + xmlFile + " to " + backup +
    79                                ", cannot migrate client " + i +
    80                                " from Jetty 5 class " + OLD_CLASS +
    81                                " to Jetty 6 class " + NEW_CLASS);
     77                               ", cannot migrate " + client);
    8278                continue;
    8379            }
    84             File baseEep = new File(ctx.getBaseDir(), "eepsite");
     80            File baseEep = new File(ctx.getBaseDir(), JETTY6_TEMPLATE_DIR);
    8581            // jetty.xml existed before in jetty 5 version, so check this new file
    8682            // and if it doesn't exist we can't continue
     
    8884            if (!baseContext.exists()) {
    8985                System.err.println("WARNING: Cannot find new XML file template " + baseContext +
    90                                ", cannot migrate client " + i +
    91                                " from Jetty 5 class " + OLD_CLASS +
    92                                " to Jetty 6 class " + NEW_CLASS);
     86                               ", cannot migrate " + client);
    9387                continue;
    9488            }
     
    9791            if (!ok) {
    9892                System.err.println("WARNING: Failed to modify XML file " + xmlFile +
    99                                ", cannot migrate client " + i +
    100                                " from Jetty 5 class " + OLD_CLASS +
    101                                " to Jetty 6 class " + NEW_CLASS);
     93                               ", cannot migrate " + client);
    10294                continue;
    10395            }
    10496            // now we're committed, so don't check any more failure codes
     97            WorkingDir.migrateJettyXml(baseEep, eepsite, "jetty-ssl.xml", "./eepsite/", newPath);
    10598            (new File(eepsite, "contexts")).mkdir();
    10699            WorkingDir.migrateJettyXml(baseEep, eepsite, BASE_CONTEXT, "./eepsite/", newPath);
     
    115108            app.className = NEW_CLASS;
    116109            shouldSave = true;
    117             System.err.println("WARNING: Migrated client " + i + " from Jetty 5 class " + OLD_CLASS +
    118                                " to Jetty 6 class " + NEW_CLASS + ".\n" +
    119                                "Check the following files in " + baseEep +
     110            System.err.println("WARNING: Migrated " + client + '\n' +
     111                               "Check the following files in " + eepsite +
    120112                               ": jetty.xml, " + BASE_CONTEXT + ", and " + CGI_CONTEXT + "\n" +
    121                                "Your old jetty.xml was saved as jetty5.xml\n" +
     113                               "Your old jetty.xml was saved as " + backup + '\n' +
    122114                               "If you modified your jetty.xml to change ports, thread limits, etc, you MUST\n" +
    123115                               "edit it to change them again. Your port was reset to 7658.");
     
    126118            File cfgFile = ClientAppConfig.configFile(ctx);
    127119            File backup = new File(cfgFile.getAbsolutePath() + ".jetty5");
     120            if (backup.exists())
     121                backup = new File(cfgFile.getAbsolutePath() + ctx.random().nextInt());
    128122            boolean ok = WorkingDir.copyFile(cfgFile, backup);
    129123            if (ok) {
    130124                ClientAppConfig.writeClientAppConfig(ctx, apps);
    131125                System.err.println("WARNING: Migrated clients config file " + cfgFile +
    132                                " from Jetty 5 class " + OLD_CLASS +
    133                                " to Jetty 6 class " + NEW_CLASS + "\n" +
    134                                "Your old clients config file was saved as " + cfgFile + ".jetty5");
     126                               " from Jetty 5 " + OLD_CLASS +
     127                               " to Jetty 6 " + NEW_CLASS + "\n" +
     128                               "Your old clients config file was saved as " + backup);
    135129            }
    136130        }
  • router/java/src/net/i2p/router/startup/WorkingDir.java

    rbeb6d1f4 rb5f97d0  
    149149        // this one must be after MIGRATE_BASE
    150150        File oldEep = new File(oldDirf, "eepsite");
    151         File newEep = new File(oldDirf, "eepsite");
     151        File newEep = new File(dirf, "eepsite");
    152152        String newPath = newEep.getAbsolutePath() + File.separatorChar;
    153153        success &= migrateJettyXml(oldEep, newEep, "jetty.xml", "./eepsite/", newPath);
     
    246246                out.println(s);
    247247            }
    248             System.err.println("Copied clients.config with modifications");
     248            System.err.println("Copied " + oldFile + " with modifications");
    249249            return true;
    250250        } catch (IOException ioe) {
    251251            if (in != null) {
    252                 System.err.println("FAILED copy clients.config");
     252                System.err.println("FAILED copy " + oldFile + ": " + ioe);
    253253                return false;
    254254            }
     
    281281            }
    282282            out.println("<!-- Modified by I2P User dir migration script -->");
    283             System.err.println("Copied " + filename + " with modifications");
     283            System.err.println("Copied " + oldFile + " with modifications");
    284284            return true;
    285285        } catch (IOException ioe) {
    286286            if (in != null) {
    287                 System.err.println("FAILED copy " + filename);
     287                System.err.println("FAILED copy " + oldFile + ": " + ioe);
    288288                return false;
    289289            }
     
    358358            System.err.println("Copied " + src.getPath());
    359359        } catch (IOException ioe) {
    360             System.err.println("FAILED copy " + src.getPath());
     360            System.err.println("FAILED copy " + src.getPath() + ": " + ioe);
    361361            rv = false;
    362362        } finally {
Note: See TracChangeset for help on using the changeset viewer.