karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject karaf git commit: KARAF-4166 - Introduce karaf.lock.exclusive property to prevent slave instance to start
Date Fri, 08 Jan 2016 08:26:06 GMT
Repository: karaf
Updated Branches:
  refs/heads/karaf-3.0.x e9b92ac92 -> b2ec798b3


KARAF-4166 - Introduce karaf.lock.exclusive property to prevent slave instance to start


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/b2ec798b
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/b2ec798b
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/b2ec798b

Branch: refs/heads/karaf-3.0.x
Commit: b2ec798b3fcdef6bd8183db7fc6c83da4f7e6c6d
Parents: e9b92ac
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Fri Jan 8 09:25:25 2016 +0100
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Fri Jan 8 09:25:25 2016 +0100

----------------------------------------------------------------------
 .../main/resources/resources/etc/system.properties |  4 ++++
 .../karaf/instance/resources/etc/system.properties | 17 +++++++++++++++++
 .../org/apache/karaf/main/ConfigProperties.java    |  4 ++++
 main/src/main/java/org/apache/karaf/main/Main.java |  8 +++++++-
 4 files changed, 32 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/b2ec798b/assemblies/features/framework/src/main/resources/resources/etc/system.properties
----------------------------------------------------------------------
diff --git a/assemblies/features/framework/src/main/resources/resources/etc/system.properties
b/assemblies/features/framework/src/main/resources/resources/etc/system.properties
index 95cb83c..b4f493b 100644
--- a/assemblies/features/framework/src/main/resources/resources/etc/system.properties
+++ b/assemblies/features/framework/src/main/resources/resources/etc/system.properties
@@ -142,3 +142,7 @@ karaf.secured.services = (&(osgi.command.scope=*)(osgi.command.function=*))
 # You can specify the location of the lock file using the
 # karaf.lock.dir=/path/to/the/directory/containing/the/lock
 #
+# By default, the slave instances start but are passive.
+# If you want to prevent the slave instances startup, you can use
+# the karaf.lock.exclusive property (false by default):
+# karaf.lock.exclusive=true

http://git-wip-us.apache.org/repos/asf/karaf/blob/b2ec798b/instance/core/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties
----------------------------------------------------------------------
diff --git a/instance/core/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties
b/instance/core/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties
index df36f27..5a7b8af 100644
--- a/instance/core/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties
+++ b/instance/core/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties
@@ -118,3 +118,20 @@ karaf.secured.services = (&(osgi.command.scope=*)(osgi.command.function=*))
 #java.security.policy=${karaf.etc}/all.policy
 #org.osgi.framework.security=osgi
 #org.osgi.framework.trust.repositories=${karaf.etc}/trustStore.ks
+
+#
+# HA/Lock configuration
+#
+# Karaf uses a lock mechanism to know which instance is the master (HA)
+# The lock can be on the filesystem (default) or on a database.
+#
+# See http://karaf.apache.org/manual/latest/users-guide/failover.html for details.
+#
+# Even using a single instance, Karaf creates the lock file
+# You can specify the location of the lock file using the
+# karaf.lock.dir=/path/to/the/directory/containing/the/lock
+#
+# By default, the slave instances start but are passive.
+# If you want to prevent the slave instances startup, you can use
+# the karaf.lock.exclusive property (false by default):
+# karaf.lock.exclusive=true
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf/blob/b2ec798b/main/src/main/java/org/apache/karaf/main/ConfigProperties.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/ConfigProperties.java b/main/src/main/java/org/apache/karaf/main/ConfigProperties.java
index ac4498e..1b7adcb 100644
--- a/main/src/main/java/org/apache/karaf/main/ConfigProperties.java
+++ b/main/src/main/java/org/apache/karaf/main/ConfigProperties.java
@@ -110,6 +110,8 @@ public class ConfigProperties {
 
     private static final String PROPERTY_LOCK_LEVEL = "karaf.lock.level";
 
+    private static final String PROPERTY_LOCK_EXCLUSIVE = "karaf.lock.exclusive";
+
     private static final String DEFAULT_REPO = "karaf.default.repository";
     
     private static final String KARAF_FRAMEWORK = "karaf.framework";
@@ -158,6 +160,7 @@ public class ConfigProperties {
     int lockStartLevel = 1;
     int lockDefaultBootLevel = 1;
     int lockDelay;
+    boolean lockExclusive;
     int shutdownTimeout = 5 * 60 * 1000;
     boolean useLock;
     String lockClass;
@@ -222,6 +225,7 @@ public class ConfigProperties {
         System.setProperty(Constants.FRAMEWORK_BEGINNING_STARTLEVEL, Integer.toString(this.defaultStartLevel));
         this.lockStartLevel = Integer.parseInt(props.getProperty(PROPERTY_LOCK_LEVEL, Integer.toString(lockStartLevel)));
               
         this.lockDelay = Integer.parseInt(props.getProperty(PROPERTY_LOCK_DELAY, DEFAULT_LOCK_DELAY));
+        this.lockExclusive = Boolean.parseBoolean(props.getProperty(PROPERTY_LOCK_EXCLUSIVE,
"false"));
         this.props.setProperty(Constants.FRAMEWORK_BEGINNING_STARTLEVEL, Integer.toString(lockDefaultBootLevel));
         this.shutdownTimeout = Integer.parseInt(props.getProperty(KARAF_SHUTDOWN_TIMEOUT,
Integer.toString(shutdownTimeout)));
         this.useLock = Boolean.parseBoolean(props.getProperty(PROPERTY_USE_LOCK, "true"));

http://git-wip-us.apache.org/repos/asf/karaf/blob/b2ec798b/main/src/main/java/org/apache/karaf/main/Main.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/Main.java b/main/src/main/java/org/apache/karaf/main/Main.java
index 9f01190..edd4ef0 100644
--- a/main/src/main/java/org/apache/karaf/main/Main.java
+++ b/main/src/main/java/org/apache/karaf/main/Main.java
@@ -302,7 +302,13 @@ public class Main {
                     lockCallback.lockLost();
                 }
             } else {
-                lockCallback.waitingForLock();
+                if (config.lockExclusive) {
+                    LOG.log(Level.SEVERE, "Can't lock, and lock is exclusive");
+                    System.err.println("Can't lock (another instance is running), and lock
is exclusive");
+                    System.exit(5);
+                } else {
+                    lockCallback.waitingForLock();
+                }
             }
             Thread.sleep(config.lockDelay);
         }


Mime
View raw message