3 # Licensed to the Apache Software Foundation (ASF) under one or more
4 # contributor license agreements. See the NOTICE file distributed with
5 # this work for additional information regarding copyright ownership.
6 # The ASF licenses this file to You under the Apache License, Version 2.0
7 # (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
19 DIRNAME=`dirname "$0"`
20 PROGNAME=`basename "$0"`
23 # Sourcing environment settings for karaf similar to tomcats setenv
25 KARAF_SCRIPT="instance"
27 if [ -f "$DIRNAME/setenv" ]; then
32 # Check/Set up some easily accessible MIN/MAX params for JVM mem usage
34 if [ "x$JAVA_MIN_MEM" = "x" ]; then
38 if [ "x$JAVA_MAX_MEM" = "x" ]; then
44 echo "${PROGNAME}: $*"
53 # OS specific support (must be 'true' or 'false').
72 # For AIX, set an environment variable
74 export LDR_CNTRL=MAXDATA=0xB0000000@DSA
80 # Use the maximum available, or set MAX_FD != -1 to use that
81 if [ "x$MAX_FD" = "x" ]; then
85 # Increase the maximum file descriptors if we can
86 if [ "$os400" = "false" ] && [ "$cygwin" = "false" ]; then
87 MAX_FD_LIMIT=`ulimit -H -n`
88 if [ "$MAX_FD_LIMIT" != 'unlimited' ]; then
90 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ]; then
92 MAX_FD="$MAX_FD_LIMIT"
95 ulimit -n $MAX_FD > /dev/null
96 # echo "ulimit -n" `ulimit -n`
98 warn "Could not set maximum file descriptor limit: $MAX_FD"
101 warn "Could not query system maximum file descriptor limit: $MAX_FD_LIMIT"
108 if [ "x$KARAF_HOME" != "x" ]; then
109 warn "Ignoring predefined value for KARAF_HOME"
112 # In POSIX shells, CDPATH may cause cd to write to stdout
113 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
115 KARAF_HOME=`cd "$DIRNAME/.."; pwd`
116 if [ ! -d "$KARAF_HOME" ]; then
117 die "KARAF_HOME is not valid: $KARAF_HOME"
122 if [ "x$KARAF_BASE" != "x" ]; then
123 if [ ! -d "$KARAF_BASE" ]; then
124 die "KARAF_BASE is not valid: $KARAF_BASE"
127 KARAF_BASE=$KARAF_HOME
132 if [ "x$KARAF_DATA" != "x" ]; then
133 if [ ! -d "$KARAF_DATA" ]; then
134 die "KARAF_DATA is not valid: $KARAF_DATA"
137 KARAF_DATA=$KARAF_BASE/data
142 if [ "x$KARAF_ETC" != "x" ]; then
143 if [ ! -d "$KARAF_ETC" ]; then
144 die "KARAF_ETC is not valid: $KARAF_ETC"
147 KARAF_ETC=$KARAF_BASE/etc
152 # Support for loading native libraries
153 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:$KARAF_BASE/lib:$KARAF_HOME/lib"
155 # For Cygwin, set PATH from LD_LIBRARY_PATH
157 LD_LIBRARY_PATH=`cygpath --path --windows "$LD_LIBRARY_PATH"`
158 PATH="$PATH;$LD_LIBRARY_PATH"
161 export LD_LIBRARY_PATH
166 while [ -h "${dst}" ] ; do
168 link=`expr "$ls" : '.*-> \(.*\)$'`
169 if expr "$link" : '/.*' > /dev/null; then
172 dst="`dirname "${dst}"`/$link"
175 local bas=`basename "${dst}"`
176 local dir=`dirname "${dst}"`
177 if [ "$bas" != "$dir" ]; then
178 dst="`pathCanonical "$dir"`/$bas"
180 echo "${dst}" | sed -e 's#//#/#g' -e 's#/./#/#g' -e 's#/[^/]*/../#/#g'
184 # Setup the Java Virtual Machine
186 [ -n "$JAVA" ] && JAVA=`cygpath --unix "$JAVA"`
187 [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
190 if [ "x$JAVA_HOME" = "x" ] && [ "$darwin" = "true" ]; then
191 JAVA_HOME="$(/usr/libexec/java_home)"
193 if [ "x$JAVA" = "x" ] && [ -r /etc/gentoo-release ] ; then
194 JAVA_HOME=`java-config --jre-home`
196 if [ "x$JAVA" = "x" ]; then
197 if [ "x$JAVA_HOME" != "x" ]; then
198 if [ ! -d "$JAVA_HOME" ]; then
199 die "JAVA_HOME is not valid: $JAVA_HOME"
201 JAVA="$JAVA_HOME/bin/java"
203 warn "JAVA_HOME not set; results may vary"
205 JAVA=`expr "$JAVA" : '.*is \(.*\)$'`
206 if [ "x$JAVA" = "x" ]; then
207 die "java command not found"
211 if [ "x$JAVA_HOME" = "x" ]; then
212 JAVA_HOME="$(dirname $(dirname $(pathCanonical "$JAVA")))"
217 #echo "`$JAVA -version`"
218 # This service should call `java -version`,
219 # read stdout, and look for hints
220 if $JAVA -version 2>&1 | grep "^IBM" ; then
222 # on OS/400, java -version does not contain IBM explicitly
228 # echo "JVM vendor is $JVM_VENDOR"
231 setupDebugOptions() {
232 if [ "x$JAVA_OPTS" = "x" ]; then
233 JAVA_OPTS="$DEFAULT_JAVA_OPTS"
237 # Set Debug options if enabled
238 if [ "x$KARAF_DEBUG" != "x" ]; then
239 # Use the defaults if JAVA_DEBUG_OPTS was not set
240 if [ "x$JAVA_DEBUG_OPTS" = "x" ]; then
241 JAVA_DEBUG_OPTS="$DEFAULT_JAVA_DEBUG_OPTS"
244 JAVA_OPTS="$JAVA_DEBUG_OPTS $JAVA_OPTS"
245 warn "Enabling Java debug options: $JAVA_DEBUG_OPTS"
250 DEFAULT_JAVA_OPTS="-Xms$JAVA_MIN_MEM -Xmx$JAVA_MAX_MEM "
252 #Set the JVM_VENDOR specific JVM flags
253 if [ "$JVM_VENDOR" = "SUN" ]; then
255 # Check some easily accessible MIN/MAX params for JVM mem usage
257 if [ "x$JAVA_PERM_MEM" != "x" ]; then
258 DEFAULT_JAVA_OPTS="$DEFAULT_JAVA_OPTS -XX:PermSize=$JAVA_PERM_MEM"
260 if [ "x$JAVA_MAX_PERM_MEM" != "x" ]; then
261 DEFAULT_JAVA_OPTS="$DEFAULT_JAVA_OPTS -XX:MaxPermSize=$JAVA_MAX_PERM_MEM"
263 DEFAULT_JAVA_OPTS="-server $DEFAULT_JAVA_OPTS -Dcom.sun.management.jmxremote"
264 elif [ "$JVM_VENDOR" = "IBM" ]; then
266 DEFAULT_JAVA_OPTS="$DEFAULT_JAVA_OPTS"
268 DEFAULT_JAVA_OPTS="-Xverify:none -Xdump:heap -Xlp $DEFAULT_JAVA_OPTS"
270 DEFAULT_JAVA_OPTS="-Xverify:none $DEFAULT_JAVA_OPTS"
274 # Add the jars in the lib dir
275 for file in "$KARAF_HOME"/lib/*.jar
277 if [ -z "$CLASSPATH" ]; then
280 CLASSPATH="$CLASSPATH:$file"
283 DEFAULT_JAVA_DEBUG_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
286 ## TODO: Move to conf/profiler/yourkit.{sh|cmd}
288 # Uncomment to enable YourKit profiling
289 #DEFAULT_JAVA_DEBUG_OPTS="-Xrunyjpagent"
293 # Determine if there is special OS handling we must perform
296 # Unlimit the number of file descriptors if possible
299 # Locate the Karaf home directory
302 # Locate the Karaf base directory
305 # Locate the Karaf data directory
308 # Locate the Karaf etc directory
311 # Setup the native library path
314 # Locate the Java VM to execute
317 # Determine the JVM vendor
320 # Setup default options
323 # Install debug options
330 CLASSPATH="${KARAF_HOME}/system/org/apache/karaf/instance/org.apache.karaf.instance.command/3.0.1/org.apache.karaf.instance.command-3.0.1.jar:${KARAF_HOME}/system/org/apache/karaf/instance/org.apache.karaf.instance.core/3.0.1/org.apache.karaf.instance.core-3.0.1.jar:${KARAF_HOME}/system/org/apache/karaf/shell/org.apache.karaf.shell.console/3.0.1/org.apache.karaf.shell.console-3.0.1.jar:${KARAF_HOME}/system/org/apache/karaf/shell/org.apache.karaf.shell.table/3.0.1/org.apache.karaf.shell.table-3.0.1.jar:${KARAF_HOME}/system/org/apache/aries/blueprint/org.apache.aries.blueprint.api/1.0.0/org.apache.aries.blueprint.api-1.0.0.jar:${KARAF_HOME}/system/org/apache/aries/blueprint/org.apache.aries.blueprint.core/1.4.0/org.apache.aries.blueprint.core-1.4.0.jar:${KARAF_HOME}/system/org/apache/aries/blueprint/org.apache.aries.blueprint.cm/1.0.3/org.apache.aries.blueprint.cm-1.0.3.jar:${KARAF_HOME}/system/org/ops4j/pax/logging/pax-logging-api/1.7.2/pax-logging-api-1.7.2.jar:${KARAF_HOME}/system/org/apache/felix/org.apache.felix.framework/4.2.1/org.apache.felix.framework-4.2.1.jar:${KARAF_HOME}/system/jline/jline/2.11/jline-2.11.jar:$CLASSPATH"
333 KARAF_HOME=`cygpath --path --windows "$KARAF_HOME"`
334 KARAF_BASE=`cygpath --path --windows "$KARAF_BASE"`
335 KARAF_DATA=`cygpath --path --windows "$KARAF_DATA"`
336 KARAF_ETC=`cygpath --path --windows "$KARAF_ETC"`
337 CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
340 exec "$JAVA" $JAVA_OPTS -Dkaraf.instances="${KARAF_HOME}/instances" -Dkaraf.home="$KARAF_HOME" -Dkaraf.base="$KARAF_BASE" -Dkaraf.etc="$KARAF_ETC" -Djava.io.tmpdir="$KARAF_DATA/tmp" -Djava.util.logging.config.file="$KARAF_BASE/etc/java.util.logging.properties" $KARAF_OPTS $OPTS -classpath "$CLASSPATH" org.apache.karaf.instance.main.Execute "$@"