fix stop button; catch and log exceptions better

This commit is contained in:
zzz
2010-02-11 21:41:54 +00:00
parent 62308f26bc
commit f265db4037
5 changed files with 29 additions and 11 deletions

View File

@ -72,8 +72,9 @@ public class ConfigClientsHandler extends FormHandler {
PluginStarter.stopPlugin(_context, app); PluginStarter.stopPlugin(_context, app);
PluginStarter.deletePlugin(_context, app); PluginStarter.deletePlugin(_context, app);
addFormNotice(_("Deleted plugin {0}", app)); addFormNotice(_("Deleted plugin {0}", app));
} catch (IOException e) { } catch (Throwable e) {
addFormError(_("Error deleting plugin {0}", app) + ": " + e); addFormError(_("Error deleting plugin {0}", app) + ": " + e);
_log.error("Error deleting plugin " + app, e);
} }
} }
return; return;
@ -84,8 +85,11 @@ public class ConfigClientsHandler extends FormHandler {
String app = _action.substring(5); String app = _action.substring(5);
try { try {
PluginStarter.stopPlugin(_context, app); PluginStarter.stopPlugin(_context, app);
} catch (IOException e) {}
addFormNotice(_("Stopped plugin {0}", app)); addFormNotice(_("Stopped plugin {0}", app));
} catch (Throwable e) {
addFormError(_("Error stopping plugin {0}", app) + ": " + e);
_log.error("Error stopping plugin " + app, e);
}
return; return;
} }
@ -247,8 +251,9 @@ public class ConfigClientsHandler extends FormHandler {
path = new File(path, app + ".war"); path = new File(path, app + ".war");
WebAppStarter.startWebApp(_context, s, app, path.getAbsolutePath()); WebAppStarter.startWebApp(_context, s, app, path.getAbsolutePath());
addFormNotice(_("WebApp") + " <a href=\"/" + app + "/\">" + _(app) + "</a> " + _("started") + '.'); addFormNotice(_("WebApp") + " <a href=\"/" + app + "/\">" + _(app) + "</a> " + _("started") + '.');
} catch (Exception ioe) { } catch (Throwable e) {
addFormError(_("Failed to start") + ' ' + _(app) + " " + ioe + '.'); addFormError(_("Failed to start") + ' ' + _(app) + " " + e + '.');
_log.error("Failed to start webapp " + app, e);
} }
return; return;
} }

View File

@ -181,7 +181,7 @@ public class ConfigClientsHelper extends HelperBase {
if (showEditButton && (!edit) && !ro) if (showEditButton && (!edit) && !ro)
buf.append("<button type=\"submit\" name=\"edit\" value=\"Edit ").append(index).append("\" >" + _("Edit") + "<span class=hide> ").append(index).append("</span></button>"); buf.append("<button type=\"submit\" name=\"edit\" value=\"Edit ").append(index).append("\" >" + _("Edit") + "<span class=hide> ").append(index).append("</span></button>");
if (showStopButton && (!edit)) if (showStopButton && (!edit))
buf.append("<button type=\"submit\" name=\"edit\" value=\"Stop ").append(index).append("\" >" + _("Stop") + "<span class=hide> ").append(index).append("</span></button>"); buf.append("<button type=\"submit\" name=\"action\" value=\"Stop ").append(index).append("\" >" + _("Stop") + "<span class=hide> ").append(index).append("</span></button>");
if (showUpdateButton && (!edit) && !ro) { if (showUpdateButton && (!edit) && !ro) {
buf.append("<button type=\"submit\" name=\"action\" value=\"Check ").append(index).append("\" >" + _("Check for updates") + "<span class=hide> ").append(index).append("</span></button>"); buf.append("<button type=\"submit\" name=\"action\" value=\"Check ").append(index).append("\" >" + _("Check for updates") + "<span class=hide> ").append(index).append("</span></button>");
buf.append("<button type=\"submit\" name=\"action\" value=\"Update ").append(index).append("\" >" + _("Update") + "<span class=hide> ").append(index).append("</span></button>"); buf.append("<button type=\"submit\" name=\"action\" value=\"Update ").append(index).append("\" >" + _("Update") + "<span class=hide> ").append(index).append("</span></button>");

View File

@ -50,6 +50,7 @@ public class PluginStarter implements Runnable {
startPlugins(_context); startPlugins(_context);
} }
/** this shouldn't throw anything */
static void startPlugins(RouterContext ctx) { static void startPlugins(RouterContext ctx) {
Log log = ctx.logManager().getLog(PluginStarter.class); Log log = ctx.logManager().getLog(PluginStarter.class);
Properties props = pluginProperties(); Properties props = pluginProperties();
@ -61,7 +62,7 @@ public class PluginStarter implements Runnable {
try { try {
if (!startPlugin(ctx, app)) if (!startPlugin(ctx, app))
log.error("Failed to start plugin: " + app); log.error("Failed to start plugin: " + app);
} catch (Exception e) { } catch (Throwable e) {
log.error("Failed to start plugin: " + app, e); log.error("Failed to start plugin: " + app, e);
} }
} }
@ -69,7 +70,10 @@ public class PluginStarter implements Runnable {
} }
} }
/** @return true on success */ /**
* @return true on success
* @throws just about anything, caller would be wise to catch Throwable
*/
static boolean startPlugin(RouterContext ctx, String appName) throws Exception { static boolean startPlugin(RouterContext ctx, String appName) throws Exception {
Log log = ctx.logManager().getLog(PluginStarter.class); Log log = ctx.logManager().getLog(PluginStarter.class);
File pluginDir = new File(ctx.getAppDir(), PluginUpdateHandler.PLUGIN_DIR + '/' + appName); File pluginDir = new File(ctx.getAppDir(), PluginUpdateHandler.PLUGIN_DIR + '/' + appName);
@ -159,7 +163,10 @@ public class PluginStarter implements Runnable {
return true; return true;
} }
/** @return true on success */ /**
* @return true on success
* @throws just about anything, caller would be wise to catch Throwable
*/
static boolean stopPlugin(RouterContext ctx, String appName) throws IOException { static boolean stopPlugin(RouterContext ctx, String appName) throws IOException {
Log log = ctx.logManager().getLog(PluginStarter.class); Log log = ctx.logManager().getLog(PluginStarter.class);
File pluginDir = new File(ctx.getAppDir(), PluginUpdateHandler.PLUGIN_DIR + '/' + appName); File pluginDir = new File(ctx.getAppDir(), PluginUpdateHandler.PLUGIN_DIR + '/' + appName);

View File

@ -308,7 +308,10 @@ public class PluginUpdateHandler extends UpdateHandler {
if (!PluginStarter.stopPlugin(_context, appName)) { if (!PluginStarter.stopPlugin(_context, appName)) {
// failed, ignore // failed, ignore
} }
} catch (IOException e) {} // ignore } catch (Throwable e) {
// no updateStatus() for this one
_log.error("Error stopping plugin " + appName, e);
}
} else { } else {
if (Boolean.valueOf(props.getProperty("update-only")).booleanValue()) { if (Boolean.valueOf(props.getProperty("update-only")).booleanValue()) {
@ -347,8 +350,9 @@ public class PluginUpdateHandler extends UpdateHandler {
updateStatus("<b>" + _("Plugin {0} installed and started", appName) + "</b>"); updateStatus("<b>" + _("Plugin {0} installed and started", appName) + "</b>");
else else
updateStatus("<b>" + _("Plugin {0} installed but failed to start, check logs", appName) + "</b>"); updateStatus("<b>" + _("Plugin {0} installed but failed to start, check logs", appName) + "</b>");
} catch (Exception e) { } catch (Throwable e) {
updateStatus("<b>" + _("Plugin {0} installed but failed to start", appName) + ": " + e + "</b>"); updateStatus("<b>" + _("Plugin {0} installed but failed to start", appName) + ": " + e + "</b>");
_log.error("Error starting plugin " + appName, e);
} }
} }
} }

View File

@ -30,6 +30,7 @@ public class WebAppStarter {
/** /**
* adds and starts * adds and starts
* @throws just about anything, caller would be wise to catch Throwable
*/ */
static void startWebApp(I2PAppContext ctx, Server server, String appName, String warPath) throws Exception { static void startWebApp(I2PAppContext ctx, Server server, String appName, String warPath) throws Exception {
File tmpdir = new File(ctx.getTempDir(), "jetty-work-" + appName + ctx.random().nextInt()); File tmpdir = new File(ctx.getTempDir(), "jetty-work-" + appName + ctx.random().nextInt());
@ -61,6 +62,7 @@ public class WebAppStarter {
/** /**
* stop it * stop it
* @throws just about anything, caller would be wise to catch Throwable
*/ */
static void stopWebApp(Server server, String appName) { static void stopWebApp(Server server, String appName) {
// this will return a new context if one does not exist // this will return a new context if one does not exist