karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject [2/2] karaf git commit: [KARAF-4564] [KARAF-4852] [KARAF-4865] Improve the main karaf script * use /bin/sh * do not rely on readlink, but use 'ls -l' * check exit code when changing directory * verify ulimit availability * use 'command -v' instead o
Date Tue, 06 Dec 2016 23:25:37 GMT
[KARAF-4564] [KARAF-4852] [KARAF-4865] Improve the main karaf script
 * use /bin/sh
 * do not rely on readlink, but use 'ls -l'
 * check exit code when changing directory
 * verify ulimit availability
 * use 'command -v' instead of 'type' 
 * support spaces in the JAVA path
 * do not use {} expansion for file names
 * fix endorsed/ext dirs on cygwin/mingw


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

Branch: refs/heads/master
Commit: b1fda013db9827502aff0b5a9a31c34110f66423
Parents: c31a03a
Author: Guillaume Nodet <gnodet@apache.org>
Authored: Wed Dec 7 00:06:39 2016 +0100
Committer: Guillaume Nodet <gnodet@apache.org>
Committed: Wed Dec 7 00:06:39 2016 +0100

----------------------------------------------------------------------
 .../base/src/main/resources/resources/bin/karaf | 94 +++++++++++---------
 1 file changed, 53 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/b1fda013/assemblies/features/base/src/main/resources/resources/bin/karaf
----------------------------------------------------------------------
diff --git a/assemblies/features/base/src/main/resources/resources/bin/karaf b/assemblies/features/base/src/main/resources/resources/bin/karaf
index c65f4ae..ee8a45a 100755
--- a/assemblies/features/base/src/main/resources/resources/bin/karaf
+++ b/assemblies/features/base/src/main/resources/resources/bin/karaf
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 #    Licensed to the Apache Software Foundation (ASF) under one or more
 #    contributor license agreements.  See the NOTICE file distributed with
@@ -18,14 +18,15 @@
 
 realpath() {
   OURPWD=${PWD}
-  cd "$(dirname "${1}")"
-  LINK=$(readlink "$(basename "${1}")")
+  cd "$(dirname "${1}")" || exit 2
+  LINK=$(ls -l "$(basename "${1}")" | awk -F"-> " '{print $2}')
   while [ "${LINK}" ]; do
-    cd "$(dirname "${LINK}")"
-    LINK=$(readlink "$(basename "${1}")")
+	  echo "link: ${LINK}" >&2
+    cd "$(dirname "${LINK}")" || exit 2
+    LINK=$(ls -l "$(basename "${1}")" | awk -F"-> " '{print $2}')
   done
   REALPATH="${PWD}/$(basename "${1}")"
-  cd "${OURPWD}"
+  cd "${OURPWD}" || exit 2
   echo "${REALPATH}"
 }
 
@@ -104,8 +105,8 @@ unlimitFD() {
     fi
 
     # Increase the maximum file descriptors if we can
-    if [ "${os400}" = "false" ] && [ "${cygwin}" = "false" ]; then
-        if [ "${MAX_FD}" = "maximum" -o "${MAX_FD}" = "max" ]; then
+    if [ "x$(command -v ulimit)" != "x" ] && [ "${os400}" = "false" ] ; then
+        if [ "${MAX_FD}" = "maximum" ] || [ "${MAX_FD}" = "max" ]; then
             MAX_FD_LIMIT=$(ulimit -H -n)
             if [ $? -eq 0 ]; then
                 # use the system max
@@ -128,7 +129,7 @@ locateHome() {
         # In POSIX shells, CDPATH may cause cd to write to stdout
         (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
         # KARAF_HOME is not provided, fall back to default
-        KARAF_HOME=$(cd "${DIRNAME}/.."; pwd)
+        KARAF_HOME=$(cd "${DIRNAME}/.." || exit 2; pwd)
     fi
 
     if [ ! -d "${KARAF_HOME}" ]; then
@@ -219,8 +220,7 @@ locateJava() {
             JAVA="${JAVA_HOME}/bin/java"
         else
             warn "JAVA_HOME not set; results may vary"
-            JAVA=$(type java)
-            JAVA=$(expr "${JAVA}" : '.* \(/.*\)$')
+            JAVA=$(command -v java)
             if [ "x${JAVA}" = "x" ]; then
                 die "java command not found"
             fi
@@ -248,11 +248,10 @@ detectJVM() {
 
 checkJvmVersion() {
     # echo "$(${JAVA} -version)"
-    VERSION=$(${JAVA} -version 2>&1 | egrep '"([0-9].[0-9]\..*[0-9]).*"' | awk '{print
substr($3,2,length($3)-2)}' | awk '{print substr($1, 3, 3)}' | sed -e 's;\.;;g')
+    VERSION=$("${JAVA}" -version 2>&1 | egrep '"([0-9].[0-9]\..*[0-9]).*"' | awk '{print
substr($3,2,length($3)-2)}' | awk '{print substr($1, 3, 3)}' | sed -e 's;\.;;g')
     if [ "x${VERSION}" = "x" ]; then
        VERSION=90
     fi
-    # echo ${VERSION}
     if [ "${VERSION}" -lt "60" ]; then
         echo "JVM must be greater than 1.6"
         exit 1;
@@ -297,7 +296,7 @@ setupDefaults() {
     #Set the JVM_VENDOR specific JVM flags
     if [ "${JVM_VENDOR}" = "SUN" ]; then
         # permgen was removed in Java 8
-        VERSION=$(${JAVA} -version 2>&1 | egrep '"([0-9].[0-9]\..*[0-9]).*"' | awk
'{print substr($3,2,length($3)-2)}' | awk '{print substr($1, 3, 3)}' | sed -e 's;\.;;g')
+        VERSION=$("${JAVA}" -version 2>&1 | egrep '"([0-9].[0-9]\..*[0-9]).*"' | awk
'{print substr($3,2,length($3)-2)}' | awk '{print substr($1, 3, 3)}' | sed -e 's;\.;;g')
         if [ "x${VERSION}" = "x" ]; then
             VERSION=90
         fi
@@ -408,7 +407,7 @@ run() {
     while [ "${1}" != "" ]; do
         case ${1} in
             'clean')
-                rm -rf "${KARAF_DATA:?}"/{.[^.],.??*,*}
+                rm -rf "${KARAF_DATA:?}"
                 shift
                 ;;
             'debug')
@@ -456,7 +455,7 @@ run() {
                 ;;
         esac
     done
-   
+
     JAVA_ENDORSED_DIRS="${JAVA_HOME}/jre/lib/endorsed:${JAVA_HOME}/lib/endorsed:${KARAF_HOME}/lib/endorsed"
     JAVA_EXT_DIRS="${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext:${KARAF_HOME}/lib/ext"
     if ${cygwin}; then
@@ -471,7 +470,7 @@ run() {
         JAVA_ENDORSED_DIRS=$(cygpath --path --windows "${JAVA_ENDORSED_DIRS}")
         JAVA_EXT_DIRS=$(cygpath --path --windows "${JAVA_EXT_DIRS}")
     fi
-    cd "${KARAF_BASE}"
+    cd "${KARAF_BASE}" || exit 2
 
     if [ -z "${KARAF_EXEC}" ]; then
         KARAF_EXEC=""
@@ -494,32 +493,45 @@ run() {
 
         if [ "${ROOT_INSTANCE_RUNNING}" = "false" ] || [ "${CHECK_ROOT_INSTANCE_RUNNING}"
= "false" ] ; then
             if [ "${VERSION}" -gt "80" ]; then
-                JDK_89_OPTS="--add-exports=java.base/sun.net.www.protocol.http=ALL-UNNAMED"
-                JDK_89_OPTS="${JDK_89_OPTS} --add-exports=java.base/sun.net.www.protocol.https=ALL-UNNAMED"
-                JDK_89_OPTS="${JDK_89_OPTS} --add-exports=java.base/sun.net.www.protocol.jar=ALL-UNNAMED"
-                JDK_89_OPTS="${JDK_89_OPTS} --add-exports=java.xml.bind/com.sun.xml.internal.bind.v2.runtime=ALL-UNNAMED"
-                JDK_89_OPTS="${JDK_89_OPTS} --add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED"
-                JDK_89_OPTS="${JDK_89_OPTS} --add-exports=jdk.naming.rmi/com.sun.jndi.url.rmi=ALL-UNNAMED"
-                JDK_89_OPTS="${JDK_89_OPTS} --add-modules java.annotations.common,java.corba,java.transaction,java.xml.bind,java.xml.ws"
+                ${KARAF_EXEC} "${JAVA}" ${JAVA_OPTS} \
+                    --add-exports=java.base/sun.net.www.protocol.http=ALL-UNNAMED \
+                    --add-exports=java.base/sun.net.www.protocol.https=ALL-UNNAMED \
+                    --add-exports=java.base/sun.net.www.protocol.jar=ALL-UNNAMED \
+                    --add-exports=java.xml.bind/com.sun.xml.internal.bind.v2.runtime=ALL-UNNAMED
\
+                    --add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED \
+                    --add-exports=jdk.naming.rmi/com.sun.jndi.url.rmi=ALL-UNNAMED \
+                    --add-modules java.annotations.common,java.corba,java.transaction,java.xml.bind,java.xml.ws
\
+                    -Dkaraf.instances="${KARAF_HOME}/instances" \
+                    -Dkaraf.home="${KARAF_HOME}" \
+                    -Dkaraf.base="${KARAF_BASE}" \
+                    -Dkaraf.data="${KARAF_DATA}" \
+                    -Dkaraf.etc="${KARAF_ETC}" \
+                    -Dkaraf.restart.jvm.supported=true \
+                    -Djava.io.tmpdir="${KARAF_DATA}/tmp" \
+                    -Djava.util.logging.config.file="${KARAF_BASE}/etc/java.util.logging.properties"
\
+                    ${KARAF_SYSTEM_OPTS} \
+                    ${KARAF_OPTS} \
+                    ${OPTS} \
+                    -classpath "${CLASSPATH}" \
+                    ${MAIN} "$@"
             else
-                JDK_89_OPTS="-Djava.endorsed.dirs=${JAVA_ENDORSED_DIRS}"
-                JDK_89_OPTS="${JDK_89_OPTS} -Djava.ext.dirs=${JAVA_EXT_DIRS}"
+                ${KARAF_EXEC} "${JAVA}" ${JAVA_OPTS} \
+                    -Djava.endorsed.dirs="${JAVA_ENDORSED_DIRS}" \
+                    -Djava.ext.dirs="${JAVA_EXT_DIRS}" \
+                    -Dkaraf.instances="${KARAF_HOME}/instances" \
+                    -Dkaraf.home="${KARAF_HOME}" \
+                    -Dkaraf.base="${KARAF_BASE}" \
+                    -Dkaraf.data="${KARAF_DATA}" \
+                    -Dkaraf.etc="${KARAF_ETC}" \
+                    -Dkaraf.restart.jvm.supported=true \
+                    -Djava.io.tmpdir="${KARAF_DATA}/tmp" \
+                    -Djava.util.logging.config.file="${KARAF_BASE}/etc/java.util.logging.properties"
\
+                    ${KARAF_SYSTEM_OPTS} \
+                    ${KARAF_OPTS} \
+                    ${OPTS} \
+                    -classpath "${CLASSPATH}" \
+                    ${MAIN} "$@"
             fi
-            ${KARAF_EXEC} "${JAVA}" ${JAVA_OPTS} \
-                ${JDK_89_OPTS} \
-                -Dkaraf.instances="${KARAF_HOME}/instances" \
-                -Dkaraf.home="${KARAF_HOME}" \
-                -Dkaraf.base="${KARAF_BASE}" \
-                -Dkaraf.data="${KARAF_DATA}" \
-                -Dkaraf.etc="${KARAF_ETC}" \
-                -Dkaraf.restart.jvm.supported=true \
-                -Djava.io.tmpdir="${KARAF_DATA}/tmp" \
-                -Djava.util.logging.config.file="${KARAF_BASE}/etc/java.util.logging.properties"
\
-                ${KARAF_SYSTEM_OPTS} \
-                ${KARAF_OPTS} \
-                ${OPTS} \
-                -classpath "${CLASSPATH}" \
-                ${MAIN} "$@"
         else
             die "There is a Root instance already running with name ${ROOT_INSTANCE_NAME}
and pid ${ROOT_INSTANCE_PID}"
         fi


Mime
View raw message