Gert Vanthienen | c4f3d35 | 2009-09-24 23:18:33 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 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 |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 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. |
| 17 | # |
| 18 | # $Id: karaf 979 2005-11-30 22:50:55Z bsnyder $ |
| 19 | # |
| 20 | |
| 21 | DIRNAME=`dirname $0` |
| 22 | PROGNAME=`basename $0` |
| 23 | |
| 24 | # |
| 25 | # Check/Set up some easily accessible MIN/MAX params for JVM mem usage |
| 26 | # |
| 27 | |
| 28 | if [ "x$JAVA_MIN_MEM" = "x" ]; then |
| 29 | JAVA_MIN_MEM=128M |
| 30 | export JAVA_MIN_MEM |
| 31 | fi |
| 32 | |
| 33 | if [ "x$JAVA_MAX_MEM" = "x" ]; then |
| 34 | JAVA_MAX_MEM=512M |
| 35 | export JAVA_MAX_MEM |
| 36 | fi |
| 37 | |
| 38 | warn() { |
| 39 | echo "${PROGNAME}: $*" |
| 40 | } |
| 41 | |
| 42 | die() { |
| 43 | warn "$*" |
| 44 | exit 1 |
| 45 | } |
| 46 | |
| 47 | maybeSource() { |
| 48 | file="$1" |
| 49 | if [ -f "$file" ] ; then |
| 50 | . $file |
| 51 | fi |
| 52 | } |
| 53 | |
| 54 | detectOS() { |
| 55 | # OS specific support (must be 'true' or 'false'). |
| 56 | cygwin=false; |
| 57 | darwin=false; |
| 58 | aix=false; |
| 59 | os400=false; |
| 60 | case "`uname`" in |
| 61 | CYGWIN*) |
| 62 | cygwin=true |
| 63 | ;; |
| 64 | Darwin*) |
| 65 | darwin=true |
| 66 | ;; |
| 67 | AIX*) |
| 68 | aix=true |
| 69 | ;; |
| 70 | OS400*) |
| 71 | os400=true |
| 72 | ;; |
| 73 | esac |
| 74 | # For AIX, set an environment variable |
| 75 | if $aix; then |
| 76 | export LDR_CNTRL=MAXDATA=0xB0000000@DSA |
| 77 | export IBM_JAVA_HEAPDUMP_TEXT=true |
| 78 | echo $LDR_CNTRL |
| 79 | fi |
| 80 | } |
| 81 | |
| 82 | unlimitFD() { |
| 83 | # Use the maximum available, or set MAX_FD != -1 to use that |
| 84 | if [ "x$MAX_FD" = "x" ]; then |
| 85 | MAX_FD="maximum" |
| 86 | fi |
| 87 | |
| 88 | # Increase the maximum file descriptors if we can |
| 89 | if [ "$os400" = "false" ] && [ "$cygwin" = "false" ]; then |
| 90 | MAX_FD_LIMIT=`ulimit -H -n` |
| 91 | if [ "$MAX_FD_LIMIT" != 'unlimited' ]; then |
| 92 | if [ $? -eq 0 ]; then |
| 93 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ]; then |
| 94 | # use the system max |
| 95 | MAX_FD="$MAX_FD_LIMIT" |
| 96 | fi |
| 97 | |
| 98 | ulimit -n $MAX_FD > /dev/null |
| 99 | # echo "ulimit -n" `ulimit -n` |
| 100 | if [ $? -ne 0 ]; then |
| 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" |
| 102 | fi |
| 103 | else |
| 104 | warn "Could not query system maximum file descriptor limit: $MAX_FD_LIMIT" |
| 105 | fi |
| 106 | fi |
| 107 | fi |
| 108 | } |
| 109 | |
| 110 | locateHome() { |
| 111 | if [ "x$KARAF_HOME" != "x" ]; then |
| 112 | warn "Ignoring predefined value for KARAF_HOME" |
| 113 | fi |
| 114 | |
| 115 | # In POSIX shells, CDPATH may cause cd to write to stdout |
| 116 | (unset CDPATH) >/dev/null 2>&1 && unset CDPATH |
| 117 | |
| 118 | KARAF_HOME=`cd $DIRNAME/..; pwd` |
| 119 | if [ ! -d "$KARAF_HOME" ]; then |
| 120 | die "KARAF_HOME is not valid: $KARAF_HOME" |
| 121 | fi |
| 122 | } |
| 123 | |
| 124 | locateBase() { |
| 125 | if [ "x$KARAF_BASE" != "x" ]; then |
| 126 | if [ ! -d "$KARAF_BASE" ]; then |
| 127 | die "KARAF_BASE is not valid: $KARAF_BASE" |
| 128 | fi |
| 129 | else |
| 130 | KARAF_BASE=$KARAF_HOME |
| 131 | fi |
| 132 | } |
| 133 | |
| 134 | setupNativePath() { |
| 135 | # Support for loading native libraries |
| 136 | LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:$KARAF_BASE/lib:$KARAF_HOME/lib" |
| 137 | |
| 138 | # For Cygwin, set PATH from LD_LIBRARY_PATH |
| 139 | if $cygwin; then |
| 140 | LD_LIBRARY_PATH=`cygpath --path --windows "$LD_LIBRARY_PATH"` |
| 141 | PATH="$PATH;$LD_LIBRARY_PATH" |
| 142 | export PATH |
| 143 | fi |
| 144 | export LD_LIBRARY_PATH |
| 145 | } |
| 146 | |
| 147 | locateJava() { |
| 148 | # Setup the Java Virtual Machine |
| 149 | if $cygwin ; then |
| 150 | [ -n "$JAVA" ] && JAVA=`cygpath --unix "$JAVA"` |
| 151 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` |
| 152 | fi |
| 153 | |
| 154 | if [ "x$JAVA" = "x" ]; then |
| 155 | if [ "x$JAVA_HOME" = "x" ] && [ "$darwin" = "true" ]; then |
| 156 | JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home |
| 157 | fi |
| 158 | if [ "x$JAVA_HOME" != "x" ]; then |
| 159 | if [ ! -d "$JAVA_HOME" ]; then |
| 160 | die "JAVA_HOME is not valid: $JAVA_HOME" |
| 161 | fi |
| 162 | JAVA="$JAVA_HOME/bin/java" |
| 163 | else |
| 164 | warn "JAVA_HOME not set; results may vary" |
| 165 | JAVA="java" |
| 166 | fi |
| 167 | fi |
| 168 | } |
| 169 | |
| 170 | detectJVM() { |
| 171 | #echo "`$JAVA -version`" |
| 172 | # This service should call `java -version`, |
| 173 | # read stdout, and look for hints |
| 174 | if $JAVA -version 2>&1 | grep "^IBM" ; then |
| 175 | JVM_VENDOR="IBM" |
| 176 | # on OS/400, java -version does not contain IBM explicitly |
| 177 | elif $os400; then |
| 178 | JVM_VENDOR="IBM" |
| 179 | else |
| 180 | JVM_VENDOR="SUN" |
| 181 | fi |
| 182 | # echo "JVM vendor is $JVM_VENDOR" |
| 183 | } |
| 184 | |
| 185 | setupDebugOptions() { |
| 186 | if [ "x$JAVA_OPTS" = "x" ]; then |
| 187 | JAVA_OPTS="$DEFAULT_JAVA_OPTS" |
| 188 | fi |
| 189 | export JAVA_OPTS |
| 190 | |
| 191 | # Set Debug options if enabled |
| 192 | if [ "x$KARAF_DEBUG" != "x" ]; then |
| 193 | # Use the defaults if JAVA_DEBUG_OPTS was not set |
| 194 | if [ "x$JAVA_DEBUG_OPTS" = "x" ]; then |
| 195 | JAVA_DEBUG_OPTS="$DEFAULT_JAVA_DEBUG_OPTS" |
| 196 | fi |
| 197 | |
| 198 | JAVA_OPTS="$JAVA_DEBUG_OPTS $JAVA_OPTS" |
| 199 | warn "Enabling Java debug options: $JAVA_DEBUG_OPTS" |
| 200 | fi |
| 201 | } |
| 202 | |
| 203 | setupDefaults() { |
| 204 | DEFAULT_JAVA_OPTS="-Xms$JAVA_MIN_MEM -Xmx$JAVA_MAX_MEM " |
| 205 | |
| 206 | #Set the JVM_VENDOR specific JVM flags |
| 207 | if [ "$JVM_VENDOR" = "SUN" ]; then |
| 208 | DEFAULT_JAVA_OPTS="-server $DEFAULT_JAVA_OPTS -Dcom.sun.management.jmxremote" |
| 209 | elif [ "$JVM_VENDOR" = "IBM" ]; then |
| 210 | if $os400; then |
| 211 | DEFAULT_JAVA_OPTS="$DEFAULT_JAVA_OPTS" |
| 212 | elif $aix; then |
| 213 | DEFAULT_JAVA_OPTS="-Xverify:none -Xlp $DEFAULT_JAVA_OPTS" |
| 214 | else |
| 215 | DEFAULT_JAVA_OPTS="-Xverify:none $DEFAULT_JAVA_OPTS" |
| 216 | fi |
| 217 | fi |
| 218 | |
| 219 | # Add the jars in the lib dir |
| 220 | for file in $KARAF_HOME/lib/*.jar |
| 221 | do |
| 222 | if [ -z "$CLASSPATH" ]; then |
| 223 | CLASSPATH="$file" |
| 224 | else |
| 225 | CLASSPATH="$CLASSPATH:$file" |
| 226 | fi |
| 227 | done |
| 228 | DEFAULT_JAVA_DEBUG_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005" |
| 229 | |
| 230 | ## |
| 231 | ## TODO: Move to conf/profiler/yourkit.{sh|cmd} |
| 232 | ## |
| 233 | # Uncomment to enable YourKit profiling |
| 234 | #DEFAULT_JAVA_DEBUG_OPTS="-Xrunyjpagent" |
| 235 | } |
| 236 | |
| 237 | init() { |
| 238 | # Determine if there is special OS handling we must perform |
| 239 | detectOS |
| 240 | |
| 241 | # Unlimit the number of file descriptors if possible |
| 242 | unlimitFD |
| 243 | |
| 244 | # Locate the Karaf home directory |
| 245 | locateHome |
| 246 | |
| 247 | # Locate the Karaf base directory |
| 248 | locateBase |
| 249 | |
| 250 | # Setup the native library path |
| 251 | setupNativePath |
| 252 | |
| 253 | # Locate the Java VM to execute |
| 254 | locateJava |
| 255 | |
| 256 | # Determine the JVM vendor |
| 257 | detectJVM |
| 258 | |
| 259 | # Setup default options |
| 260 | setupDefaults |
| 261 | |
| 262 | # Install debug options |
| 263 | setupDebugOptions |
| 264 | |
| 265 | } |
| 266 | |
| 267 | run() { |
| 268 | if $cygwin; then |
| 269 | KARAF_HOME=`cygpath --path --windows "$KARAF_HOME"` |
| 270 | KARAF_BASE=`cygpath --path --windows "$KARAF_BASE"` |
| 271 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` |
| 272 | fi |
Guillaume Nodet | 0c02aa9 | 2009-11-23 16:46:33 +0000 | [diff] [blame] | 273 | exec $JAVA $JAVA_OPTS -Dkaraf.home="$KARAF_HOME" -Dkaraf.base="$KARAF_BASE" -Djava.util.logging.config.file=$KARAF_BASE/etc/java.util.logging.properties -jar "$KARAF_HOME/lib/karaf-client.jar" osgi:shutdown "$@" |
Gert Vanthienen | c4f3d35 | 2009-09-24 23:18:33 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | main() { |
| 277 | init |
| 278 | run "$@" |
| 279 | } |
| 280 | |
| 281 | main "$@" |