SSL Wizard: Stop and restart Jetty if running

Make JettyStart restartable
RouterAppManager workaround for JettyStart becoming untracked after stop
This commit is contained in:
zzz
2018-05-03 19:29:13 +00:00
parent 9a7b58259f
commit b31ebfe368
3 changed files with 78 additions and 2 deletions

View File

@@ -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 <a href=\"/configclients\">the configure clients page</a>");
}
} else if (ok) {
out.println("Unable to restart Jetty server");
out.println("You must start (or stop and restart) the Jetty server on <a href=\"/configclients\">the configure clients page</a>");
}
// rewrite i2ptunnel.config
Integer i443 = Integer.valueOf(443);

View File

@@ -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);

View File

@@ -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;
}