You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by pi...@apache.org on 2013/01/16 07:26:46 UTC
svn commit: r1433832 - in /karaf/trunk:
assemblies/features/framework/src/main/resources/resources/etc/
instance/core/src/main/resources/org/apache/karaf/instance/resources/etc/
main/src/main/java/org/apache/karaf/main/ system/command/src/main/java/org...
Author: pieber
Date: Wed Jan 16 06:26:46 2013
New Revision: 1433832
URL: http://svn.apache.org/viewvc?rev=1433832&view=rev
Log:
[KARAF-1563] Add feature to clean cache only or the entire data dir
Signed-off-by: Andreas Pieber <an...@gmail.com>
Modified:
karaf/trunk/assemblies/features/framework/src/main/resources/resources/etc/system.properties
karaf/trunk/instance/core/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties
karaf/trunk/main/src/main/java/org/apache/karaf/main/ConfigProperties.java
karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/Shutdown.java
karaf/trunk/system/core/src/main/java/org/apache/karaf/system/SystemService.java
karaf/trunk/system/core/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java
karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/SystemMBean.java
karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/internal/System.java
Modified: karaf/trunk/assemblies/features/framework/src/main/resources/resources/etc/system.properties
URL: http://svn.apache.org/viewvc/karaf/trunk/assemblies/features/framework/src/main/resources/resources/etc/system.properties?rev=1433832&r1=1433831&r2=1433832&view=diff
==============================================================================
--- karaf/trunk/assemblies/features/framework/src/main/resources/resources/etc/system.properties (original)
+++ karaf/trunk/assemblies/features/framework/src/main/resources/resources/etc/system.properties Wed Jan 16 06:26:46 2013
@@ -74,6 +74,15 @@ xml.catalog.files=
#
jline.nobell=true
+#
+# Deletes the entire karaf.data directory at every start
+#
+karaf.clean.all=false
+
+#
+# Deletes the karaf.data/cache directory at every start
+#
+karaf.clean.cache=false
#
# ServiceMix specs options
Modified: karaf/trunk/instance/core/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties
URL: http://svn.apache.org/viewvc/karaf/trunk/instance/core/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties?rev=1433832&r1=1433831&r2=1433832&view=diff
==============================================================================
--- karaf/trunk/instance/core/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties (original)
+++ karaf/trunk/instance/core/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties Wed Jan 16 06:26:46 2013
@@ -50,6 +50,16 @@ karaf.default.repository=system
karaf.shell.init.script=${karaf.home}/etc/shell.init.script
#
+# Deletes the entire karaf.data directory at every start
+#
+karaf.clean.all=false
+
+#
+# Deletes the karaf.data/cache directory at every start
+#
+karaf.clean.cache=false
+
+#
# Default role name used for console authorization (JMX, SSH and WEB)
# The syntax is the following:
# [classname:]principal
Modified: karaf/trunk/main/src/main/java/org/apache/karaf/main/ConfigProperties.java
URL: http://svn.apache.org/viewvc/karaf/trunk/main/src/main/java/org/apache/karaf/main/ConfigProperties.java?rev=1433832&r1=1433831&r2=1433832&view=diff
==============================================================================
--- karaf/trunk/main/src/main/java/org/apache/karaf/main/ConfigProperties.java (original)
+++ karaf/trunk/main/src/main/java/org/apache/karaf/main/ConfigProperties.java Wed Jan 16 06:26:46 2013
@@ -169,7 +169,24 @@ public class ConfigProperties {
Utils.deleteDirectory(this.karafData);
this.karafData = Utils.getKarafDirectory(PROP_KARAF_DATA, ENV_KARAF_DATA, new File(karafBase, "data"), true, true);
}
-
+
+ File cleanAllIndicatorFile = new File(karafData, "clean_all");
+ File cleanCacheIndicatorFile = new File(karafData, "clean_cache");
+ if (Boolean.getBoolean("karaf.clean.all") || cleanAllIndicatorFile.exists()) {
+ if (cleanAllIndicatorFile.exists()) {
+ cleanAllIndicatorFile.delete();
+ }
+ Utils.deleteDirectory(karafData);
+ } else {
+ if (Boolean.getBoolean("karaf.clean.cache") || cleanCacheIndicatorFile.exists()) {
+ if (cleanCacheIndicatorFile.exists()) {
+ cleanCacheIndicatorFile.delete();
+ }
+ File karafCache = Utils.getKarafDirectory(PROP_KARAF_DATA, ENV_KARAF_DATA, new File(karafData, "cache"), true, true);
+ Utils.deleteDirectory(karafCache);
+ }
+ }
+
this.karafInstances = Utils.getKarafDirectory(PROP_KARAF_INSTANCES, ENV_KARAF_INSTANCES, new File(karafHome, "instances"), false, false);
Package p = Package.getPackage("org.apache.karaf.main");
Modified: karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/Shutdown.java
URL: http://svn.apache.org/viewvc/karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/Shutdown.java?rev=1433832&r1=1433831&r2=1433832&view=diff
==============================================================================
--- karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/Shutdown.java (original)
+++ karaf/trunk/system/command/src/main/java/org/apache/karaf/system/commands/Shutdown.java Wed Jan 16 06:26:46 2013
@@ -19,6 +19,7 @@ package org.apache.karaf.system.commands
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
+import org.apache.karaf.system.SystemService;
/**
* Command to shut down Karaf container.
@@ -35,8 +36,12 @@ public class Shutdown extends AbstractSy
@Option(name = "-h", aliases = "--halt", description = "Halt the Karaf container.", required = false, multiValued = false)
boolean halt = false;
- @Option(name = "-c", aliases = "--clean", description = "Clean the Karaf container (working directory) during reboot.", required = false, multiValued = false)
- boolean clean = false;
+ @Option(name = "-c", aliases = {"--clean", "--clean-all", "-ca"}, description = "Force a clean restart by deleting the data directory")
+ private boolean cleanAll;
+
+ @Option(name = "-cc", aliases = {"--clean-cache", "-cc"}, description = "Force a clean restart by deleting the cache directory")
+ private boolean cleanCache;
+
@Argument(name = "time", index = 0, description = "Shutdown after a specified delay. The time argument can have different" +
" formats. First, it can be an abolute time in the format hh:mm, in which hh is the hour (1 or 2 digits) and mm" +
@@ -48,7 +53,7 @@ public class Shutdown extends AbstractSy
if (force) {
if (reboot) {
- systemService.reboot(time, clean);
+ systemService.reboot(time, determineSwipeType());
} else {
systemService.halt(time);
}
@@ -79,7 +84,7 @@ public class Shutdown extends AbstractSy
String str = sb.toString();
if (str.equals("yes")) {
if (reboot) {
- systemService.reboot(time, clean);
+ systemService.reboot(time, determineSwipeType());
} else {
systemService.halt(time);
}
@@ -88,4 +93,13 @@ public class Shutdown extends AbstractSy
}
}
+ private SystemService.Swipe determineSwipeType() {
+ if (cleanAll) {
+ return SystemService.Swipe.ALL;
+ } else if (cleanCache) {
+ return SystemService.Swipe.CACHE;
+ }
+ return SystemService.Swipe.NONE;
+ }
+
}
Modified: karaf/trunk/system/core/src/main/java/org/apache/karaf/system/SystemService.java
URL: http://svn.apache.org/viewvc/karaf/trunk/system/core/src/main/java/org/apache/karaf/system/SystemService.java?rev=1433832&r1=1433831&r2=1433832&view=diff
==============================================================================
--- karaf/trunk/system/core/src/main/java/org/apache/karaf/system/SystemService.java (original)
+++ karaf/trunk/system/core/src/main/java/org/apache/karaf/system/SystemService.java Wed Jan 16 06:26:46 2013
@@ -22,6 +22,18 @@ package org.apache.karaf.system;
public interface SystemService {
/**
+ * Types defining what to remove on a restart of Karaf
+ */
+ public enum Swipe {
+ /** Delete nothing; simple restart */
+ NONE,
+ /** Delete only the cache; everything else remains */
+ CACHE,
+ /** Forces a clean restart by removing the working directory; this option is compatible to the former clean method. */
+ ALL
+ }
+
+ /**
* Halt the Karaf container.
*/
void halt() throws Exception;
@@ -52,7 +64,7 @@ public interface SystemService {
* to wait. The word now is an alias for +0.
* @param clean Force a clean restart by deleting the working directory.
*/
- void reboot(String time, boolean clean) throws Exception;
+ void reboot(String time, Swipe clean) throws Exception;
/**
* Set the system start level.
Modified: karaf/trunk/system/core/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/system/core/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java?rev=1433832&r1=1433831&r2=1433832&view=diff
==============================================================================
--- karaf/trunk/system/core/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java (original)
+++ karaf/trunk/system/core/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java Wed Jan 16 06:26:46 2013
@@ -57,11 +57,11 @@ public class SystemServiceImpl implement
}
public void reboot() throws Exception {
- reboot(null, false);
+ reboot(null, Swipe.NONE);
}
- public void reboot(String time, boolean cleanup) throws Exception {
- reboot(timeToSleep(time), true);
+ public void reboot(String time, Swipe cleanup) throws Exception {
+ reboot(timeToSleep(time), cleanup);
}
private void shutdown(final long sleep) {
@@ -77,13 +77,17 @@ public class SystemServiceImpl implement
}.start();
}
- private void reboot(final long sleep, final boolean clean) {
+ private void reboot(final long sleep, final Swipe clean) {
new Thread() {
public void run() {
try {
sleepWithMsg(sleep, "Reboot in " + sleep / 1000 / 60 + " minute(s)");
System.setProperty("karaf.restart", "true");
- System.setProperty("karaf.restart.clean", Boolean.toString(clean));
+ if (clean.equals(Swipe.ALL)) {
+ System.setProperty("karaf.clean.all", "true");
+ } else if (clean.equals(Swipe.CACHE)) {
+ System.setProperty("karaf.clean.cache", "true");
+ }
bundleContext.getBundle(0).stop();
} catch (Exception e) {
LOGGER.error("Reboot error", e);
Modified: karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/SystemMBean.java
URL: http://svn.apache.org/viewvc/karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/SystemMBean.java?rev=1433832&r1=1433831&r2=1433832&view=diff
==============================================================================
--- karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/SystemMBean.java (original)
+++ karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/SystemMBean.java Wed Jan 16 06:26:46 2013
@@ -24,7 +24,9 @@ public interface SystemMBean {
void halt() throws Exception;
void halt(String time) throws Exception;
void reboot() throws Exception;
- void reboot(String time, boolean clean) throws Exception;
+ void reboot(String time) throws Exception;
+ void rebootCleanCache(String time) throws Exception;
+ void rebootCleanAll(String time) throws Exception;
void setStartLevel(int startLevel) throws Exception;
int getStartLevel() throws Exception;
Modified: karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/internal/System.java
URL: http://svn.apache.org/viewvc/karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/internal/System.java?rev=1433832&r1=1433831&r2=1433832&view=diff
==============================================================================
--- karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/internal/System.java (original)
+++ karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/internal/System.java Wed Jan 16 06:26:46 2013
@@ -54,8 +54,16 @@ public class System extends StandardMBea
systemService.reboot();
}
- public void reboot(String time, boolean clean) throws Exception {
- systemService.reboot(time, clean);
+ public void reboot(String time) throws Exception {
+ systemService.reboot(time, SystemService.Swipe.NONE);
+ }
+
+ public void rebootCleanCache(String time) throws Exception {
+ systemService.reboot(time, SystemService.Swipe.CACHE);
+ }
+
+ public void rebootCleanAll(String time) throws Exception {
+ systemService.reboot(time, SystemService.Swipe.ALL);
}
public void setStartLevel(int startLevel) throws Exception {