diff --git a/apps/i2ptunnel/jsp/ssl.jsp b/apps/i2ptunnel/jsp/ssl.jsp index 9c8001d34..e2bbfd826 100644 --- a/apps/i2ptunnel/jsp/ssl.jsp +++ b/apps/i2ptunnel/jsp/ssl.jsp @@ -299,7 +299,63 @@ input.default { width: 1px; height: 1px; visibility: hidden; } } // stop and restart jetty - + // this only works if running already, else it isn't registered + net.i2p.app.ClientAppManager cmgr = ctx.clientAppManager(); + net.i2p.app.ClientApp jstart = cmgr.getRegisteredApp("Jetty"); + if (ok && jstart != null) { + String fullname = jstart.getDisplayName(); + if (fullname.contains(jettySSLConfigPath) || + fullname.contains(jettySSLConfigPath.replace("jetty-ssl.xml", "jetty.xml"))) { + // ok, this is probably the right ClientApp + net.i2p.app.ClientAppState state = jstart.getState(); + if (state == net.i2p.app.ClientAppState.RUNNING) { + try { + // app becomes untracked, + // see workaround in RouterAppManager + jstart.shutdown(null); + for (int i = 0; i < 20; i++) { + state = jstart.getState(); + if (state == net.i2p.app.ClientAppState.STOPPED) { + if (i < 4) { + try { Thread.sleep(1000); } catch (InterruptedException ie) { break; } + } + out.println("Jetty server stopped"); + break; + } + try { Thread.sleep(250); } catch (InterruptedException ie) { break; } + } + if (state != net.i2p.app.ClientAppState.STOPPED) + out.println("Jetty server stop failed"); + } catch (Throwable t) { + out.println("Jetty server stop failed: " + t); + } + } + if (state == net.i2p.app.ClientAppState.STOPPED) { + try { + jstart.startup(); + for (int i = 0; i < 20; i++) { + state = jstart.getState(); + if (state == net.i2p.app.ClientAppState.RUNNING) { + out.println("Jetty server started"); + break; + } + try { Thread.sleep(250); } catch (InterruptedException ie) { break; } + } + if (state != net.i2p.app.ClientAppState.RUNNING) + out.println("Jetty server start failed"); + } catch (Throwable t) { + out.println("Jetty server start failed: " + t); + ok = false; + } + } + } else { + out.println("Unable to restart Jetty server"); + out.println("You must start (or stop and restart) the Jetty server on the configure clients page"); + } + } else if (ok) { + out.println("Unable to restart Jetty server"); + out.println("You must start (or stop and restart) the Jetty server on the configure clients page"); + } // rewrite i2ptunnel.config Integer i443 = Integer.valueOf(443); diff --git a/apps/jetty/java/src/net/i2p/jetty/JettyStart.java b/apps/jetty/java/src/net/i2p/jetty/JettyStart.java index c49f883bd..75a489e2f 100644 --- a/apps/jetty/java/src/net/i2p/jetty/JettyStart.java +++ b/apps/jetty/java/src/net/i2p/jetty/JettyStart.java @@ -113,7 +113,7 @@ public class JettyStart implements ClientApp { } public synchronized void startup() { - if (_state != INITIALIZED) + if (_state != INITIALIZED && _state != STOPPED && _state != START_FAILED) return; if (_jettys.isEmpty()) { changeState(START_FAILED); diff --git a/router/java/src/net/i2p/router/startup/RouterAppManager.java b/router/java/src/net/i2p/router/startup/RouterAppManager.java index 71b8bf4d4..b320795ce 100644 --- a/router/java/src/net/i2p/router/startup/RouterAppManager.java +++ b/router/java/src/net/i2p/router/startup/RouterAppManager.java @@ -76,6 +76,26 @@ public class RouterAppManager extends ClientAppManagerImpl { Arrays.equals(e.getValue(), args)) return e.getKey(); } + // workaround for Jetty stop and restart from i2ptunnel + // app becomes untracked so look in registered + if (className.equals("net.i2p.jetty.JettyStart") && args.length > 0) { + for (ClientApp app : _registered.values()) { + if (app.getClass().getName().equals(className)) { + String dname = app.getDisplayName(); + int idx = 0; + boolean match = true; + for (String arg : args) { + idx = dname.indexOf(arg, idx); + if (idx < 0) { + match = false; + break; + } + } + if (match) + return app; + } + } + } return null; }