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 Thu, 07 Jan 2016 16:29:27 GMT
Repository: karaf
Updated Branches:
  refs/heads/master cf863ab9f -> bffcbc032


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/bffcbc03
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/bffcbc03
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/bffcbc03

Branch: refs/heads/master
Commit: bffcbc032b2f0f90431201f09830c9717b8f27c9
Parents: cf863ab
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Thu Jan 7 17:28:44 2016 +0100
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Thu Jan 7 17:28:44 2016 +0100

----------------------------------------------------------------------
 .../main/resources/resources/etc/system.properties |  4 ++++
 .../karaf/instance/resources/etc/system.properties | 17 +++++++++++++++++
 .../org/apache/karaf/main/ConfigProperties.java    |  7 +++++--
 main/src/main/java/org/apache/karaf/main/Main.java | 11 +++++++----
 4 files changed, 33 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/bffcbc03/assemblies/features/base/src/main/resources/resources/etc/system.properties
----------------------------------------------------------------------
diff --git a/assemblies/features/base/src/main/resources/resources/etc/system.properties b/assemblies/features/base/src/main/resources/resources/etc/system.properties
index 8e3cb68..5b0b376 100644
--- a/assemblies/features/base/src/main/resources/resources/etc/system.properties
+++ b/assemblies/features/base/src/main/resources/resources/etc/system.properties
@@ -143,3 +143,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
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf/blob/bffcbc03/instance/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties
----------------------------------------------------------------------
diff --git a/instance/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties
b/instance/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties
index 277c0ed..e996d7e 100644
--- a/instance/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties
+++ b/instance/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties
@@ -123,3 +123,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

http://git-wip-us.apache.org/repos/asf/karaf/blob/bffcbc03/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 1bce0b4..014b448 100644
--- a/main/src/main/java/org/apache/karaf/main/ConfigProperties.java
+++ b/main/src/main/java/org/apache/karaf/main/ConfigProperties.java
@@ -111,6 +111,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";
@@ -159,6 +161,7 @@ public class ConfigProperties {
     int lockStartLevel = 1;
     int lockDefaultBootLevel = 1;
     int lockDelay;
+    boolean lockExclusive = false;
     int shutdownTimeout = 5 * 60 * 1000;
     boolean useLock;
     String lockClass;
@@ -180,8 +183,7 @@ public class ConfigProperties {
         this.karafBase = Utils.getKarafDirectory(PROP_KARAF_BASE, ENV_KARAF_BASE, karafHome,
false, true);
         this.karafData = Utils.getKarafDirectory(PROP_KARAF_DATA, ENV_KARAF_DATA, new File(karafBase,
"data"), true, true);
         this.karafEtc = Utils.getKarafDirectory(PROP_KARAF_ETC, ENV_KARAF_ETC, new File(karafBase,
"etc"), true, true);
-        
-              
+
         this.karafInstances = Utils.getKarafDirectory(PROP_KARAF_INSTANCES, ENV_KARAF_INSTANCES,
new File(karafHome, "instances"), false, false);
 
         Package p = Package.getPackage("org.apache.karaf.main");
@@ -224,6 +226,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/bffcbc03/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 d2c77df..8719340 100644
--- a/main/src/main/java/org/apache/karaf/main/Main.java
+++ b/main/src/main/java/org/apache/karaf/main/Main.java
@@ -22,9 +22,7 @@ import java.io.BufferedReader;
 import java.io.File;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.net.URI;
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -53,7 +51,6 @@ import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
 import org.osgi.framework.FrameworkEvent;
 import org.osgi.framework.FrameworkListener;
-import org.osgi.framework.ServiceReference;
 import org.osgi.framework.launch.Framework;
 import org.osgi.framework.launch.FrameworkFactory;
 import org.osgi.framework.startlevel.BundleStartLevel;
@@ -358,7 +355,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