From: Alexis de Talhouët Date: Tue, 7 Jun 2016 23:04:15 +0000 (-0400) Subject: Bug 6027 - Can't start karaf using symbolic link X-Git-Tag: release/boron~47 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=0eda999492644870f55582837e469ee3b3729e5d;ds=sidebyside Bug 6027 - Can't start karaf using symbolic link 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 Co-Authored-By: Michael Vorburger --- diff --git a/karaf/opendaylight-karaf-resources/src/main/resources/bin/instance b/karaf/opendaylight-karaf-resources/src/main/resources/bin/instance index ca6f33439b..d7a344c483 100755 --- a/karaf/opendaylight-karaf-resources/src/main/resources/bin/instance +++ b/karaf/opendaylight-karaf-resources/src/main/resources/bin/instance @@ -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 @@ -16,8 +16,12 @@ # 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 diff --git a/karaf/opendaylight-karaf-resources/src/main/resources/bin/karaf b/karaf/opendaylight-karaf-resources/src/main/resources/bin/karaf index 483bd3fdeb..99eddab1eb 100755 --- a/karaf/opendaylight-karaf-resources/src/main/resources/bin/karaf +++ b/karaf/opendaylight-karaf-resources/src/main/resources/bin/karaf @@ -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 @@ -16,8 +16,12 @@ # 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