Bug 6027 - Can't start karaf using symbolic link 82/39982/12
authorAlexis de Talhouët <adetalhouet@inocybe.com>
Tue, 7 Jun 2016 23:04:15 +0000 (19:04 -0400)
committerTom Pantelis <tpanteli@brocade.com>
Mon, 25 Jul 2016 01:25:09 +0000 (01:25 +0000)
When executing the karaf script, it gets the DIRNAME based on $0
which is the path used to start the script. This DIRNAME is then
used to set the KARAF_HOME and multiple other KARAF_* evn variables.

Using a symbolic link, you would have, for instance, usr/bin/karaf
redirecting to /opt/opendaylight/bin/karaf.
So $0 would be usr/bin and not /opt/opendaylight/bin so the locateHome
function isn't setting the right path for the KARAF_HOME.

This ends up failing to start ODL with following ERROR:
Error: Could not find or load main class org.apache.karaf.main.Main

see:
https://github.com/opendaylight/controller/blob/master/karaf/opendaylight-karaf-resources/src/main/resources/bin/karaf#l114l126

Change-Id: I36eff657972768de7d7b90f6563addfc3dd96c0f
Signed-off-by: Alexis de Talhouët <adetalhouet@inocybe.com>
Co-Authored-By: Michael Vorburger <vorburger@redhat.com>
karaf/opendaylight-karaf-resources/src/main/resources/bin/instance
karaf/opendaylight-karaf-resources/src/main/resources/bin/karaf

index ca6f33439bf65d3ef06f61a5a99f86560e022b33..d7a344c483045c0e8f898a672d1e350174de0a12 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 #
 #    Licensed to the Apache Software Foundation (ASF) under one or more
 #    contributor license agreements.  See the NOTICE file distributed with
 #    limitations under the License.
 #
 
-DIRNAME=`dirname "$0"`
-PROGNAME=`basename "$0"`
+REALNAME=`readlink -e "$0"`
+if [ $? != 0 ]; then
+    REALNAME=$0
+fi
+DIRNAME=`dirname "$REALNAME"`
+PROGNAME=`basename "$REALNAME"`
 
 #
 # Sourcing environment settings for karaf similar to tomcats setenv
index 483bd3fdebd876995d4952bcd139db5211ba43ba..99eddab1eb94dd866d67afd1d14f147a2e28ff57 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 #
 #    Licensed to the Apache Software Foundation (ASF) under one or more
 #    contributor license agreements.  See the NOTICE file distributed with
 #    limitations under the License.
 #
 
-DIRNAME=`dirname "$0"`
-PROGNAME=`basename "$0"`
+REALNAME=`readlink -e "$0"`
+if [ $? != 0 ]; then
+    REALNAME=$0
+fi
+DIRNAME=`dirname "$REALNAME"`
+PROGNAME=`basename "$REALNAME"`
 
 #
 # Sourcing environment settings for karaf similar to tomcats setenv
@@ -194,9 +198,9 @@ locateJava() {
         [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
     fi
 
-       if [ "x$JAVA_HOME" = "x" ] && [ "$darwin" = "true" ]; then
-               JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"
-       fi
+    if [ "x$JAVA_HOME" = "x" ] && [ "$darwin" = "true" ]; then
+        JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"
+    fi
     if [ "x$JAVA" = "x" ] && [ -r /etc/gentoo-release ] ; then
         JAVA_HOME=`java-config --jre-home`
     fi