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 REALNAME=`readlink -e "$0"`
23 DIRNAME=`dirname "$REALNAME"`
24 PROGNAME=`basename "$REALNAME"`
27 # Sourcing environment settings for karaf similar to tomcats setenv
31 if [ -f "$DIRNAME/setenv" ]; then
36 # Set up some easily accessible MIN/MAX params for JVM mem usage
38 if [ "x$JAVA_MIN_MEM" = "x" ]; then
42 if [ "x$JAVA_MAX_MEM" = "x" ]; then
48 # Check the mode that initiated the script
50 if [ "x$1" != "x" ]; then
55 echo "${PROGNAME}: $*"
64 # OS specific support (must be 'true' or 'false').
83 # For AIX, set an environment variable
85 export LDR_CNTRL=MAXDATA=0xB0000000@DSA
91 # Use the maximum available, or set MAX_FD != -1 to use that
92 if [ "x$MAX_FD" = "x" ]; then
96 # Increase the maximum file descriptors if we can
97 if [ "$os400" = "false" ] && [ "$cygwin" = "false" ]; then
98 MAX_FD_LIMIT=`ulimit -H -n`
99 if [ "$MAX_FD_LIMIT" != 'unlimited' ]; then
100 if [ $? -eq 0 ]; then
101 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ]; then
103 MAX_FD="$MAX_FD_LIMIT"
106 ulimit -n $MAX_FD > /dev/null
107 # echo "ulimit -n" `ulimit -n`
108 if [ $? -ne 0 ]; then
109 warn "Could not set maximum file descriptor limit: $MAX_FD"
112 warn "Could not query system maximum file descriptor limit: $MAX_FD_LIMIT"
119 if [ "x$KARAF_HOME" != "x" ]; then
120 warn "Ignoring predefined value for KARAF_HOME"
123 # In POSIX shells, CDPATH may cause cd to write to stdout
124 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
126 KARAF_HOME=`cd "$DIRNAME/.."; pwd`
127 if [ ! -d "$KARAF_HOME" ]; then
128 die "KARAF_HOME is not valid: $KARAF_HOME"
133 if [ "x$KARAF_BASE" != "x" ]; then
134 if [ ! -d "$KARAF_BASE" ]; then
135 die "KARAF_BASE is not valid: $KARAF_BASE"
138 KARAF_BASE=$KARAF_HOME
143 if [ "x$KARAF_DATA" != "x" ]; then
144 if [ ! -d "$KARAF_DATA" ]; then
145 die "KARAF_DATA is not valid: $KARAF_DATA"
148 KARAF_DATA=$KARAF_BASE/data
153 if [ "x$KARAF_ETC" != "x" ]; then
154 if [ ! -d "$KARAF_ETC" ]; then
155 die "KARAF_ETC is not valid: $KARAF_ETC"
158 KARAF_ETC=$KARAF_BASE/etc
163 # Support for loading native libraries
164 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:$KARAF_BASE/lib:$KARAF_HOME/lib"
166 # For Cygwin, set PATH from LD_LIBRARY_PATH
168 LD_LIBRARY_PATH=`cygpath --path --windows "$LD_LIBRARY_PATH"`
169 PATH="$PATH;$LD_LIBRARY_PATH"
172 export LD_LIBRARY_PATH
177 while [ -h "${dst}" ] ; do
179 link=`expr "$ls" : '.*-> \(.*\)$'`
180 if expr "$link" : '/.*' > /dev/null; then
183 dst="`dirname "${dst}"`/$link"
186 bas=`basename "${dst}"`
187 dir=`dirname "${dst}"`
188 if [ "$bas" != "$dir" ]; then
189 dst="`pathCanonical "$dir"`/$bas"
191 echo "${dst}" | sed -e 's#//#/#g' -e 's#/./#/#g' -e 's#/[^/]*/../#/#g'
195 # Setup the Java Virtual Machine
197 [ -n "$JAVA" ] && JAVA=`cygpath --unix "$JAVA"`
198 [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
201 if [ "x$JAVA_HOME" = "x" ] && [ "$darwin" = "true" ]; then
202 JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"
204 if [ "x$JAVA" = "x" ] && [ -r /etc/gentoo-release ] ; then
205 JAVA_HOME=`java-config --jre-home`
207 if [ "x$JAVA" = "x" ]; then
208 if [ "x$JAVA_HOME" != "x" ]; then
209 if [ ! -d "$JAVA_HOME" ]; then
210 die "JAVA_HOME is not valid: $JAVA_HOME"
212 JAVA="$JAVA_HOME/bin/java"
214 warn "JAVA_HOME not set; results may vary"
216 JAVA=`expr "$JAVA" : '.* \(/.*\)$'`
217 if [ "x$JAVA" = "x" ]; then
218 die "java command not found"
222 if [ "x$JAVA_HOME" = "x" ]; then
223 JAVA_HOME="$(dirname $(dirname $(pathCanonical "$JAVA")))"
228 #echo "`$JAVA -version`"
229 # This service should call `java -version`,
230 # read stdout, and look for hints
231 if $JAVA -version 2>&1 | grep "^IBM" ; then
233 # on OS/400, java -version does not contain IBM explicitly
239 # echo "JVM vendor is $JVM_VENDOR"
243 # echo "`$JAVA -version`"
244 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'`
246 if [ "$VERSION" -lt "80" ]; then
247 echo "JVM must be 1.8.0 or greater"
252 setupDebugOptions() {
253 if [ "x$JAVA_OPTS" = "x" ]; then
254 JAVA_OPTS="$DEFAULT_JAVA_OPTS"
258 if [ "x$EXTRA_JAVA_OPTS" != "x" ]; then
259 JAVA_OPTS="$JAVA_OPTS $EXTRA_JAVA_OPTS"
262 # Set Debug options if enabled
263 if [ "x$KARAF_DEBUG" != "x" ]; then
264 # Ignore DEBUG in case of stop or client mode
265 if [ "x$MODE" = "xstop" ]; then
268 if [ "x$MODE" = "xclient" ]; then
271 # Use the defaults if JAVA_DEBUG_OPTS was not set
272 if [ "x$JAVA_DEBUG_OPTS" = "x" ]; then
273 JAVA_DEBUG_OPTS="$DEFAULT_JAVA_DEBUG_OPTS"
276 JAVA_OPTS="$JAVA_DEBUG_OPTS $JAVA_OPTS"
277 warn "Enabling Java debug options: $JAVA_DEBUG_OPTS"
282 DEFAULT_JAVA_OPTS="-Xms$JAVA_MIN_MEM -Xmx$JAVA_MAX_MEM -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass -XX:+HeapDumpOnOutOfMemoryError"
284 #Set the JVM_VENDOR specific JVM flags
285 if [ "$JVM_VENDOR" = "SUN" ]; then
286 DEFAULT_JAVA_OPTS="-server $DEFAULT_JAVA_OPTS -Dcom.sun.management.jmxremote"
287 elif [ "$JVM_VENDOR" = "IBM" ]; then
289 DEFAULT_JAVA_OPTS="$DEFAULT_JAVA_OPTS"
291 DEFAULT_JAVA_OPTS="-Xverify:none -Xdump:heap -Xlp $DEFAULT_JAVA_OPTS"
293 DEFAULT_JAVA_OPTS="-Xverify:none $DEFAULT_JAVA_OPTS"
297 # Add default security file option
298 if [ "x$ODL_JAVA_SECURITY_PROPERTIES" != "x" ]; then
299 DEFAULT_JAVA_OPTS="-Djava.security.properties="${ODL_JAVA_SECURITY_PROPERTIES}" $DEFAULT_JAVA_OPTS"
301 DEFAULT_JAVA_OPTS="-Djava.security.properties="${KARAF_ETC}/odl.java.security" $DEFAULT_JAVA_OPTS"
304 # Add the jars in the lib dir
305 for file in "$KARAF_HOME"/lib/karaf*.jar
307 if [ -z "$CLASSPATH" ]; then
310 CLASSPATH="$CLASSPATH:$file"
314 DEFAULT_JAVA_DEBUG_PORT="5005"
315 if [ "x$JAVA_DEBUG_PORT" = "x" ]; then
316 JAVA_DEBUG_PORT="$DEFAULT_JAVA_DEBUG_PORT"
318 DEFAULT_JAVA_DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$JAVA_DEBUG_PORT"
321 ## TODO: Move to conf/profiler/yourkit.{sh|cmd}
323 # Uncomment to enable YourKit profiling
324 #DEFAULT_JAVA_DEBUG_OPTS="-Xrunyjpagent"
328 # Determine if there is special OS handling we must perform
331 # Unlimit the number of file descriptors if possible
334 # Locate the Karaf home directory
337 # Locate the Karaf base directory
340 # Locate the Karaf data directory
343 # Locate the Karaf etc directory
346 # Setup the native library path
349 # Locate the Java VM to execute
352 # Determine the JVM vendor
355 # Determine the JVM version >= 1.8
358 # Setup default options
361 # Install debug options
367 OPTS="-Dkaraf.startLocalConsole=true -Dkaraf.startRemoteShell=true"
368 MAIN=org.apache.karaf.main.Main
369 while [ "$1" != "" ]; do
376 if [ "x$JAVA_DEBUG_OPTS" = "x" ]; then
377 JAVA_DEBUG_OPTS="$DEFAULT_JAVA_DEBUG_OPTS"
379 JAVA_OPTS="$JAVA_DEBUG_OPTS $JAVA_OPTS"
383 MAIN=org.apache.karaf.main.Status
387 MAIN=org.apache.karaf.main.Stop
394 OPTS="-Dkaraf.startLocalConsole=false -Dkaraf.startRemoteShell=true"
398 OPTS="-Dkaraf.startLocalConsole=true -Dkaraf.startRemoteShell=false"
407 JAVA_ENDORSED_DIRS="${JAVA_HOME}/jre/lib/endorsed:${JAVA_HOME}/lib/endorsed:${KARAF_HOME}/lib/endorsed"
408 JAVA_EXT_DIRS="${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext:${KARAF_HOME}/lib/ext"
410 KARAF_HOME=`cygpath --path --windows "$KARAF_HOME"`
411 KARAF_BASE=`cygpath --path --windows "$KARAF_BASE"`
412 KARAF_DATA=`cygpath --path --windows "$KARAF_DATA"`
413 KARAF_ETC=`cygpath --path --windows "$KARAF_ETC"`
414 CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
415 JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
416 JAVA_ENDORSED_DIRS=`cygpath --path --windows "$JAVA_ENDORSED_DIRS"`
417 JAVA_EXT_DIRS=`cygpath --path --windows "$JAVA_EXT_DIRS"`
421 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" -Djava.io.tmpdir="$KARAF_DATA/tmp" -Djava.util.logging.config.file="$KARAF_BASE/etc/java.util.logging.properties" $KARAF_OPTS $OPTS -classpath "$CLASSPATH" $MAIN "$@"