forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p' (head b7ee04ecc7a594239e977b25a52ebdabadce558e)
to branch 'i2p.i2p.zzz.jetty6' (head 2cd4a4dae8b87b9ed2128d83aff1b39e3a818556)
This commit is contained in:
@@ -8,8 +8,12 @@ import net.i2p.apps.systray.UrlLauncher;
|
||||
import net.i2p.router.Router;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.router.startup.ClientAppConfig;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
import org.tanukisoftware.wrapper.WrapperManager;
|
||||
import org.tanukisoftware.wrapper.event.WrapperControlEvent;
|
||||
import org.tanukisoftware.wrapper.event.WrapperEvent;
|
||||
import org.tanukisoftware.wrapper.event.WrapperEventListener;
|
||||
|
||||
/**
|
||||
* Handler to deal with form submissions from the service config form and act
|
||||
@@ -18,6 +22,10 @@ import org.tanukisoftware.wrapper.WrapperManager;
|
||||
*/
|
||||
public class ConfigServiceHandler extends FormHandler {
|
||||
|
||||
private static WrapperEventListener _signalHandler;
|
||||
|
||||
private static final String PROP_GRACEFUL_HUP = "router.gracefulHUP";
|
||||
|
||||
/**
|
||||
* Register two shutdown hooks, one to rekey and/or tell the wrapper we are stopping,
|
||||
* and a final one to tell the wrapper we are stopped.
|
||||
@@ -127,6 +135,79 @@ public class ConfigServiceHandler extends FormHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a handler for signals,
|
||||
* so we can handle HUP from the wrapper (non-Windows only)
|
||||
*
|
||||
* @since 0.8.13
|
||||
*/
|
||||
synchronized static void registerSignalHandler(RouterContext ctx) {
|
||||
if (ctx.hasWrapper() && _signalHandler == null &&
|
||||
!System.getProperty("os.name").startsWith("Win")) {
|
||||
_signalHandler = new SignalHandler(ctx);
|
||||
long mask = WrapperEventListener.EVENT_FLAG_CONTROL;
|
||||
WrapperManager.addWrapperEventListener(_signalHandler, mask);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister the handler for signals
|
||||
*
|
||||
* @since 0.8.13
|
||||
*/
|
||||
public synchronized static void unregisterSignalHandler() {
|
||||
if (_signalHandler != null) {
|
||||
WrapperManager.removeWrapperEventListener(_signalHandler);
|
||||
_signalHandler = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Catch signals.
|
||||
* The wrapper will potentially forward HUP, USR1, and USR2.
|
||||
* But USR1 and USR2 are used by the JVM GC and cannot be trapped.
|
||||
* So we will only get HUP.
|
||||
*
|
||||
* @since 0.8.13
|
||||
*/
|
||||
private static class SignalHandler implements WrapperEventListener {
|
||||
private final RouterContext _ctxt;
|
||||
|
||||
public SignalHandler(RouterContext ctx) {
|
||||
_ctxt = ctx;
|
||||
}
|
||||
|
||||
public void fired(WrapperEvent event) {
|
||||
if (!(event instanceof WrapperControlEvent))
|
||||
return;
|
||||
WrapperControlEvent wce = (WrapperControlEvent) event;
|
||||
Log log = _ctxt.logManager().getLog(ConfigServiceHandler.class);
|
||||
if (log.shouldLog(Log.WARN))
|
||||
log.warn("Got signal: " + wce.getControlEventName());
|
||||
int sig = wce.getControlEvent();
|
||||
switch (sig) {
|
||||
case WrapperManager.WRAPPER_CTRL_HUP_EVENT:
|
||||
if (_ctxt.getBooleanProperty(PROP_GRACEFUL_HUP)) {
|
||||
wce.consume();
|
||||
if (!(_ctxt.router().gracefulShutdownInProgress() ||
|
||||
_ctxt.router().isFinalShutdownInProgress())) {
|
||||
System.err.println("WARN: Graceful shutdown initiated by SIGHUP");
|
||||
log.logAlways(Log.WARN, "Graceful shutdown initiated by SIGHUP");
|
||||
registerWrapperNotifier(_ctxt, Router.EXIT_GRACEFUL, false);
|
||||
_ctxt.router().shutdownGracefully();
|
||||
}
|
||||
} else {
|
||||
log.log(Log.CRIT, "Hard shutdown initiated by SIGHUP");
|
||||
// JVM will call ShutdownHook if we don't do it ourselves
|
||||
//wce.consume();
|
||||
//registerWrapperNotifier(_ctxt, Router.EXIT_HARD, false);
|
||||
//_ctxt.router().shutdown(Router.EXIT_HARD);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processForm() {
|
||||
if (_action == null) return;
|
||||
@@ -194,6 +275,7 @@ public class ConfigServiceHandler extends FormHandler {
|
||||
addFormError(_("Warning: unable to install the service") + " - " + ioe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void uninstallService() {
|
||||
try {
|
||||
Runtime.getRuntime().exec("uninstall_i2p_service_winnt.bat");
|
||||
|
@@ -53,14 +53,14 @@ public class ConfigUIHelper extends HelperBase {
|
||||
* Any language-specific flag added to the icon set must be
|
||||
* added to the top-level build.xml for the updater.
|
||||
*/
|
||||
private static final String langs[] = {"ar", "da", "de", "en", "es", "fi",
|
||||
private static final String langs[] = {"ar", "da", "de", "ee", "en", "es", "fi",
|
||||
"fr", "it", "nl", "pl", "pt", "ru",
|
||||
"sv", "uk", "vi", "zh"};
|
||||
private static final String flags[] = {"lang_ar", "dk", "de", "us", "es", "fi",
|
||||
private static final String flags[] = {"lang_ar", "dk", "de", "ee", "us", "es", "fi",
|
||||
"fr", "it", "nl", "pl", "pt", "ru",
|
||||
"se", "ua", "vn", "cn"};
|
||||
private static final String xlangs[] = {_x("Arabic"), _x("Danish"),
|
||||
_x("German"), _x("English"), _x("Spanish"),_x("Finnish"),
|
||||
_x("German"), _x("Estonian"), _x("English"), _x("Spanish"), _x("Finnish"),
|
||||
_x("French"), _x("Italian"), _x("Dutch"), _x("Polish"),
|
||||
_x("Portuguese"), _x("Russian"), _x("Swedish"),
|
||||
_x("Ukrainian"), _x("Vietnamese"), _x("Chinese")};
|
||||
|
@@ -10,7 +10,7 @@ import org.mortbay.jetty.Server;
|
||||
public class LogsHelper extends HelperBase {
|
||||
public LogsHelper() {}
|
||||
|
||||
/** @since 0.8.11 */
|
||||
/** @since 0.8.12 */
|
||||
public String getJettyVersion() {
|
||||
return Server.getVersion();
|
||||
}
|
||||
|
@@ -376,9 +376,8 @@ public class NetDbRenderer {
|
||||
int cost = addr.getCost();
|
||||
if (!((style.equals("SSU") && cost == 5) || (style.equals("NTCP") && cost == 10)))
|
||||
buf.append('[').append(_("cost")).append('=').append("" + cost).append("] ");
|
||||
Properties p = new OrderedProperties();
|
||||
p.putAll(addr.getOptions());
|
||||
for (Map.Entry e : p.entrySet()) {
|
||||
Map p = addr.getOptionsMap();
|
||||
for (Map.Entry e : (Set<Map.Entry>) p.entrySet()) {
|
||||
String name = (String) e.getKey();
|
||||
String val = (String) e.getValue();
|
||||
buf.append('[').append(_(DataHelper.stripHTML(name))).append('=').append(DataHelper.stripHTML(val)).append("] ");
|
||||
@@ -387,9 +386,10 @@ public class NetDbRenderer {
|
||||
buf.append("</td></tr>\n");
|
||||
if (full) {
|
||||
buf.append("<tr><td>" + _("Stats") + ": <br><code>");
|
||||
for (Iterator iter = info.getOptions().keySet().iterator(); iter.hasNext(); ) {
|
||||
String key = (String)iter.next();
|
||||
String val = info.getOption(key);
|
||||
Map p = info.getOptionsMap();
|
||||
for (Map.Entry e : (Set<Map.Entry>) p.entrySet()) {
|
||||
String key = (String) e.getKey();
|
||||
String val = (String) e.getValue();
|
||||
buf.append(DataHelper.stripHTML(key)).append(" = ").append(DataHelper.stripHTML(val)).append("<br>\n");
|
||||
}
|
||||
buf.append("</code></td></tr>\n");
|
||||
@@ -412,7 +412,7 @@ public class NetDbRenderer {
|
||||
if (style.equals("NTCP")) {
|
||||
rv |= NTCP;
|
||||
} else if (style.equals("SSU")) {
|
||||
if (addr.getOptions().getProperty("iport0") != null)
|
||||
if (addr.getOption("iport0") != null)
|
||||
rv |= SSUI;
|
||||
else
|
||||
rv |= SSU;
|
||||
|
@@ -17,6 +17,7 @@ import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import net.i2p.CoreVersion;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.router.Job;
|
||||
@@ -27,6 +28,7 @@ import net.i2p.util.ConcurrentHashSet;
|
||||
import net.i2p.util.FileUtil;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.Translate;
|
||||
import net.i2p.util.VersionComparator;
|
||||
|
||||
import org.mortbay.jetty.handler.ContextHandlerCollection;
|
||||
|
||||
@@ -95,6 +97,41 @@ public class PluginStarter implements Runnable {
|
||||
log.error("Cannot start nonexistent plugin: " + appName);
|
||||
return false;
|
||||
}
|
||||
|
||||
Properties props = pluginProperties(ctx, appName);
|
||||
String minVersion = ConfigClientsHelper.stripHTML(props, "min-i2p-version");
|
||||
if (minVersion != null &&
|
||||
(new VersionComparator()).compare(CoreVersion.VERSION, minVersion) < 0) {
|
||||
String foo = "Plugin " + appName + " requires I2P version " + minVersion + " or higher";
|
||||
log.error(foo);
|
||||
throw new Exception(foo);
|
||||
}
|
||||
|
||||
minVersion = ConfigClientsHelper.stripHTML(props, "min-java-version");
|
||||
if (minVersion != null &&
|
||||
(new VersionComparator()).compare(System.getProperty("java.version"), minVersion) < 0) {
|
||||
String foo = "Plugin " + appName + " requires Java version " + minVersion + " or higher";
|
||||
log.error(foo);
|
||||
throw new Exception(foo);
|
||||
}
|
||||
|
||||
String jVersion = LogsHelper.jettyVersion();
|
||||
minVersion = ConfigClientsHelper.stripHTML(props, "min-jetty-version");
|
||||
if (minVersion != null &&
|
||||
(new VersionComparator()).compare(minVersion, jVersion) > 0) {
|
||||
String foo = "Plugin " + appName + " requires Jetty version " + minVersion + " or higher";
|
||||
log.error(foo);
|
||||
throw new Exception(foo);
|
||||
}
|
||||
|
||||
String maxVersion = ConfigClientsHelper.stripHTML(props, "max-jetty-version");
|
||||
if (maxVersion != null &&
|
||||
(new VersionComparator()).compare(maxVersion, jVersion) < 0) {
|
||||
String foo = "Plugin " + appName + " requires Jetty version " + maxVersion + " or lower";
|
||||
log.error(foo);
|
||||
throw new Exception(foo);
|
||||
}
|
||||
|
||||
if (log.shouldLog(Log.INFO))
|
||||
log.info("Starting plugin: " + appName);
|
||||
|
||||
@@ -113,8 +150,8 @@ public class PluginStarter implements Runnable {
|
||||
// load and start things in clients.config
|
||||
File clientConfig = new File(pluginDir, "clients.config");
|
||||
if (clientConfig.exists()) {
|
||||
Properties props = new Properties();
|
||||
DataHelper.loadProps(props, clientConfig);
|
||||
Properties cprops = new Properties();
|
||||
DataHelper.loadProps(cprops, clientConfig);
|
||||
List<ClientAppConfig> clients = ClientAppConfig.getClientApps(clientConfig);
|
||||
runClientApps(ctx, pluginDir, clients, "start");
|
||||
}
|
||||
@@ -123,7 +160,7 @@ public class PluginStarter implements Runnable {
|
||||
ContextHandlerCollection server = WebAppStarter.getConsoleServer();
|
||||
if (server != null) {
|
||||
File consoleDir = new File(pluginDir, "console");
|
||||
Properties props = RouterConsoleRunner.webAppProperties(consoleDir.getAbsolutePath());
|
||||
Properties wprops = RouterConsoleRunner.webAppProperties(consoleDir.getAbsolutePath());
|
||||
File webappDir = new File(consoleDir, "webapps");
|
||||
String fileNames[] = webappDir.list(RouterConsoleRunner.WarFilenameFilter.instance());
|
||||
if (fileNames != null) {
|
||||
@@ -138,7 +175,7 @@ public class PluginStarter implements Runnable {
|
||||
log.error("Skipping duplicate webapp " + warName + " in plugin " + appName);
|
||||
continue;
|
||||
}
|
||||
String enabled = props.getProperty(RouterConsoleRunner.PREFIX + warName + ENABLED);
|
||||
String enabled = wprops.getProperty(RouterConsoleRunner.PREFIX + warName + ENABLED);
|
||||
if (! "false".equals(enabled)) {
|
||||
if (log.shouldLog(Log.INFO))
|
||||
log.info("Starting webapp: " + warName);
|
||||
@@ -181,7 +218,6 @@ public class PluginStarter implements Runnable {
|
||||
}
|
||||
|
||||
// add summary bar link
|
||||
Properties props = pluginProperties(ctx, appName);
|
||||
String name = ConfigClientsHelper.stripHTML(props, "consoleLinkName_" + Messages.getLanguage(ctx));
|
||||
if (name == null)
|
||||
name = ConfigClientsHelper.stripHTML(props, "consoleLinkName");
|
||||
|
@@ -334,6 +334,21 @@ public class PluginUpdateHandler extends UpdateHandler {
|
||||
statusDone("<b>" + _("Plugin update requires installed plugin version {0} or lower", maxVersion) + "</b>");
|
||||
return;
|
||||
}
|
||||
oldVersion = LogsHelper.jettyVersion();
|
||||
minVersion = ConfigClientsHelper.stripHTML(props, "min-jetty-version");
|
||||
if (minVersion != null &&
|
||||
(new VersionComparator()).compare(minVersion, oldVersion) > 0) {
|
||||
to.delete();
|
||||
statusDone("<b>" + _("Plugin requires Jetty version {0} or higher", minVersion) + "</b>");
|
||||
return;
|
||||
}
|
||||
maxVersion = ConfigClientsHelper.stripHTML(props, "max-jetty-version");
|
||||
if (maxVersion != null &&
|
||||
(new VersionComparator()).compare(maxVersion, oldVersion) < 0) {
|
||||
to.delete();
|
||||
statusDone("<b>" + _("Plugin requires Jetty version {0} or lower", maxVersion) + "</b>");
|
||||
return;
|
||||
}
|
||||
|
||||
// check if it is running first?
|
||||
try {
|
||||
|
@@ -477,6 +477,7 @@ public class RouterConsoleRunner {
|
||||
ctx.addShutdownTask(new NewsShutdown(fetcher, newsThread));
|
||||
// stat summarizer registers its own hook
|
||||
ctx.addShutdownTask(new ServerShutdown());
|
||||
ConfigServiceHandler.registerSignalHandler(ctx);
|
||||
} // else log CRIT ?
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user