* Plugins:

- Only stop a plugin before update if it was running
    - Don't start a plugin after update if it was disabled
    - Disable plugin if it fails version checks at startup
This commit is contained in:
zzz
2012-01-15 16:59:33 +00:00
parent b5d77685b9
commit 3d2d60469e
2 changed files with 46 additions and 10 deletions

View File

@ -95,6 +95,7 @@ public class PluginStarter implements Runnable {
File pluginDir = new File(ctx.getConfigDir(), PluginUpdateHandler.PLUGIN_DIR + '/' + appName); File pluginDir = new File(ctx.getConfigDir(), PluginUpdateHandler.PLUGIN_DIR + '/' + appName);
if ((!pluginDir.exists()) || (!pluginDir.isDirectory())) { if ((!pluginDir.exists()) || (!pluginDir.isDirectory())) {
log.error("Cannot start nonexistent plugin: " + appName); log.error("Cannot start nonexistent plugin: " + appName);
disablePlugin(appName);
return false; return false;
} }
@ -104,6 +105,7 @@ public class PluginStarter implements Runnable {
(new VersionComparator()).compare(CoreVersion.VERSION, minVersion) < 0) { (new VersionComparator()).compare(CoreVersion.VERSION, minVersion) < 0) {
String foo = "Plugin " + appName + " requires I2P version " + minVersion + " or higher"; String foo = "Plugin " + appName + " requires I2P version " + minVersion + " or higher";
log.error(foo); log.error(foo);
disablePlugin(appName);
throw new Exception(foo); throw new Exception(foo);
} }
@ -112,6 +114,7 @@ public class PluginStarter implements Runnable {
(new VersionComparator()).compare(System.getProperty("java.version"), minVersion) < 0) { (new VersionComparator()).compare(System.getProperty("java.version"), minVersion) < 0) {
String foo = "Plugin " + appName + " requires Java version " + minVersion + " or higher"; String foo = "Plugin " + appName + " requires Java version " + minVersion + " or higher";
log.error(foo); log.error(foo);
disablePlugin(appName);
throw new Exception(foo); throw new Exception(foo);
} }
@ -121,6 +124,7 @@ public class PluginStarter implements Runnable {
(new VersionComparator()).compare(minVersion, jVersion) > 0) { (new VersionComparator()).compare(minVersion, jVersion) > 0) {
String foo = "Plugin " + appName + " requires Jetty version " + minVersion + " or higher"; String foo = "Plugin " + appName + " requires Jetty version " + minVersion + " or higher";
log.error(foo); log.error(foo);
disablePlugin(appName);
throw new Exception(foo); throw new Exception(foo);
} }
@ -129,6 +133,7 @@ public class PluginStarter implements Runnable {
(new VersionComparator()).compare(maxVersion, jVersion) < 0) { (new VersionComparator()).compare(maxVersion, jVersion) < 0) {
String foo = "Plugin " + appName + " requires Jetty version " + maxVersion + " or lower"; String foo = "Plugin " + appName + " requires Jetty version " + maxVersion + " or lower";
log.error(foo); log.error(foo);
disablePlugin(appName);
throw new Exception(foo); throw new Exception(foo);
} }
@ -334,7 +339,7 @@ public class PluginStarter implements Runnable {
Properties props = pluginProperties(); Properties props = pluginProperties();
for (Iterator iter = props.keySet().iterator(); iter.hasNext(); ) { for (Iterator iter = props.keySet().iterator(); iter.hasNext(); ) {
String name = (String)iter.next(); String name = (String)iter.next();
if (name.startsWith(PREFIX + appName)) if (name.startsWith(PREFIX + appName + '.'))
iter.remove(); iter.remove();
} }
storePluginProperties(props); storePluginProperties(props);
@ -373,6 +378,32 @@ public class PluginStarter implements Runnable {
return rv; return rv;
} }
/**
* Is the plugin enabled in plugins.config?
* Default true
*
* @since 0.8.13
*/
public static boolean isPluginEnabled(String appName) {
Properties props = pluginProperties();
String prop = PREFIX + appName + ENABLED;
return Boolean.valueOf(props.getProperty(prop, "true")).booleanValue();
}
/**
* Disable in plugins.config
*
* @since 0.8.13
*/
public static void disablePlugin(String appName) {
Properties props = pluginProperties();
String prop = PREFIX + appName + ENABLED;
if (Boolean.valueOf(props.getProperty(prop, "true")).booleanValue()) {
props.setProperty(prop, "false");
storePluginProperties(props);
}
}
/** /**
* all installed plugins whether enabled or not * all installed plugins whether enabled or not
*/ */

View File

@ -286,6 +286,7 @@ public class PluginUpdateHandler extends UpdateHandler {
return; return;
} }
boolean wasRunning = false;
File destDir = new SecureDirectory(appDir, appName); File destDir = new SecureDirectory(appDir, appName);
if (destDir.exists()) { if (destDir.exists()) {
if (Boolean.valueOf(props.getProperty("install-only")).booleanValue()) { if (Boolean.valueOf(props.getProperty("install-only")).booleanValue()) {
@ -350,14 +351,16 @@ public class PluginUpdateHandler extends UpdateHandler {
return; return;
} }
// check if it is running first? if (PluginStarter.isPluginRunning(appName, _context)) {
try { wasRunning = true;
if (!PluginStarter.stopPlugin(_context, appName)) { try {
// failed, ignore if (!PluginStarter.stopPlugin(_context, appName)) {
// failed, ignore
}
} catch (Throwable e) {
// no updateStatus() for this one
_log.error("Error stopping plugin " + appName, e);
} }
} catch (Throwable e) {
// no updateStatus() for this one
_log.error("Error stopping plugin " + appName, e);
} }
} else { } else {
@ -390,8 +393,8 @@ public class PluginUpdateHandler extends UpdateHandler {
pluginProps.setProperty(PluginStarter.PREFIX + appName + PluginStarter.ENABLED, "false"); pluginProps.setProperty(PluginStarter.PREFIX + appName + PluginStarter.ENABLED, "false");
PluginStarter.storePluginProperties(pluginProps); PluginStarter.storePluginProperties(pluginProps);
} }
} else { } else if (wasRunning || PluginStarter.isPluginEnabled(appName)) {
// start everything // start everything unless it was disabled and not running before
try { try {
if (PluginStarter.startPlugin(_context, appName)) { if (PluginStarter.startPlugin(_context, appName)) {
String linkName = ConfigClientsHelper.stripHTML(props, "consoleLinkName_" + Messages.getLanguage(_context)); String linkName = ConfigClientsHelper.stripHTML(props, "consoleLinkName_" + Messages.getLanguage(_context));
@ -411,6 +414,8 @@ public class PluginUpdateHandler extends UpdateHandler {
statusDone("<b>" + _("Plugin {0} installed but failed to start", appName) + ": " + e + "</b>"); statusDone("<b>" + _("Plugin {0} installed but failed to start", appName) + ": " + e + "</b>");
_log.error("Error starting plugin " + appName, e); _log.error("Error starting plugin " + appName, e);
} }
} else {
statusDone("<b>" + _("Plugin {0} installed", appName) + "</b>");
} }
} }