blob: 6f5d30dc1132bab68b51e063d05297a75c6f7739 [file] [log] [blame]
Guillaume Nodet05fac962009-04-27 10:01:58 +00001#!/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: servicemix 979 2005-11-30 22:50:55Z bsnyder $
19#
20
21DIRNAME=`dirname $0`
22PROGNAME=`basename $0`
23
24#
25# Check/Set up some easily accessible MIN/MAX params for JVM mem usage
26#
27
28if [ "x$JAVA_MIN_MEM" = "x" ]; then
29 JAVA_MIN_MEM=128M
30 export JAVA_MIN_MEM
31fi
32
33if [ "x$JAVA_MAX_MEM" = "x" ]; then
34 JAVA_MAX_MEM=512M
35 export JAVA_MAX_MEM
36fi
37
38warn() {
39 echo "${PROGNAME}: $*"
40}
41
42die() {
43 warn "$*"
44 exit 1
45}
46
47maybeSource() {
48 file="$1"
49 if [ -f "$file" ] ; then
50 . $file
51 fi
52}
53
54detectOS() {
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
82unlimitFD() {
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
110locateHome() {
111 if [ "x$SERVICEMIX_HOME" != "x" ]; then
112 warn "Ignoring predefined value for SERVICEMIX_HOME"
113 fi
114
115 SERVICEMIX_HOME=`cd $DIRNAME/..; pwd`
116 if [ ! -d "$SERVICEMIX_HOME" ]; then
117 die "SERVICEMIX_HOME is not valid: $SERVICEMIX_HOME"
118 fi
119}
120
121locateBase() {
122 if [ "x$SERVICEMIX_BASE" != "x" ]; then
123 if [ ! -d "$SERVICEMIX_BASE" ]; then
124 die "SERVICEMIX_BASE is not valid: $SERVICEMIX_BASE"
125 fi
126 else
127 SERVICEMIX_BASE=$SERVICEMIX_HOME
128 fi
129}
130
131setupNativePath() {
132 # Support for loading native libraries
133 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:$SERVICEMIX_BASE/lib:$SERVICEMIX_HOME/lib"
134
135 # For Cygwin, set PATH from LD_LIBRARY_PATH
136 if $cygwin; then
137 LD_LIBRARY_PATH=`cygpath --path --windows "$LD_LIBRARY_PATH"`
138 PATH="$PATH;$LD_LIBRARY_PATH"
139 export PATH
140 fi
141 export LD_LIBRARY_PATH
142}
143
144locateJava() {
145 # Setup the Java Virtual Machine
146 if $cygwin ; then
147 [ -n "$JAVA" ] && JAVA=`cygpath --unix "$JAVA"`
148 [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
149 fi
150
151 if [ "x$JAVA" = "x" ]; then
152 if [ "x$JAVA_HOME" = "x" ] && [ "$darwin" = "true" ]; then
153 JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
154 fi
155 if [ "x$JAVA_HOME" != "x" ]; then
156 if [ ! -d "$JAVA_HOME" ]; then
157 die "JAVA_HOME is not valid: $JAVA_HOME"
158 fi
159 JAVA="$JAVA_HOME/bin/java"
160 else
161 warn "JAVA_HOME not set; results may vary"
162 JAVA="java"
163 fi
164 fi
165}
166
167detectJVM() {
168 #echo "`$JAVA -version`"
169 # This service should call `java -version`,
170 # read stdout, and look for hints
171 if $JAVA -version 2>&1 | grep "^IBM" ; then
172 JVM_VENDOR="IBM"
173 # on OS/400, java -version does not contain IBM explicitly
174 elif $os400; then
175 JVM_VENDOR="IBM"
176 else
177 JVM_VENDOR="SUN"
178 fi
179 # echo "JVM vendor is $JVM_VENDOR"
180}
181
182setupDebugOptions() {
183 if [ "x$JAVA_OPTS" = "x" ]; then
184 JAVA_OPTS="$DEFAULT_JAVA_OPTS"
185 fi
186 export JAVA_OPTS
187
188 # Set Debug options if enabled
189 if [ "x$SERVICEMIX_DEBUG" != "x" ]; then
190 # Use the defaults if JAVA_DEBUG_OPTS was not set
191 if [ "x$JAVA_DEBUG_OPTS" = "x" ]; then
192 JAVA_DEBUG_OPTS="$DEFAULT_JAVA_DEBUG_OPTS"
193 fi
194
195 JAVA_OPTS="$JAVA_DEBUG_OPTS $JAVA_OPTS"
196 warn "Enabling Java debug options: $JAVA_DEBUG_OPTS"
197 fi
198}
199
200setupDefaults() {
201 DEFAULT_JAVA_OPTS="-Xms$JAVA_MIN_MEM -Xmx$JAVA_MAX_MEM "
202
203 #Set the JVM_VENDOR specific JVM flags
204 if [ "$JVM_VENDOR" = "SUN" ]; then
205 DEFAULT_JAVA_OPTS="-server $DEFAULT_JAVA_OPTS -Dcom.sun.management.jmxremote"
206 elif [ "$JVM_VENDOR" = "IBM" ]; then
207 if $os400; then
208 DEFAULT_JAVA_OPTS="$DEFAULT_JAVA_OPTS"
209 elif $aix; then
210 DEFAULT_JAVA_OPTS="-Xverify:none -Xlp $DEFAULT_JAVA_OPTS"
211 else
212 DEFAULT_JAVA_OPTS="-Xverify:none $DEFAULT_JAVA_OPTS"
213 fi
214 fi
215
216 # Add the jars in the lib dir
217 for file in $SERVICEMIX_HOME/lib/*.jar
218 do
219 if [ -z "$CLASSPATH" ]; then
220 CLASSPATH="$file"
221 else
222 CLASSPATH="$CLASSPATH:$file"
223 fi
224 done
225 DEFAULT_JAVA_DEBUG_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
226
227 ##
228 ## TODO: Move to conf/profiler/yourkit.{sh|cmd}
229 ##
230 # Uncomment to enable YourKit profiling
231 #DEFAULT_JAVA_DEBUG_OPTS="-Xrunyjpagent"
232}
233
234init() {
235 # Determine if there is special OS handling we must perform
236 detectOS
237
238 # Unlimit the number of file descriptors if possible
239 unlimitFD
240
241 # Locate the ServiceMix home directory
242 locateHome
243
244 # Locate the ServiceMix base directory
245 locateBase
246
247 # Setup the native library path
248 setupNativePath
249
250 # Locate the Java VM to execute
251 locateJava
252
253 # Determine the JVM vendor
254 detectJVM
255
256 # Setup default options
257 setupDefaults
258
259 # Install debug options
260 setupDebugOptions
261
262}
263
264run() {
265 OPTS="-Dservicemix.startLocalConsole=true -Dservicemix.startRemoteShell=true"
266 case "$1" in
267 'console')
268 shift
269 ;;
270 'server')
271 OPTS="-Dservicemix.startLocalConsole=false -Dservicemix.startRemoteShell=true"
272 shift
273 ;;
274 'client')
275 OPTS="-Dservicemix.startLocalConsole=true -Dservicemix.startRemoteShell=false"
276 shift
277 ;;
278 esac
279
280 if $cygwin; then
281 SERVICEMIX_HOME=`cygpath --path --windows "$SERVICEMIX_HOME"`
282 SERVICEMIX_BASE=`cygpath --path --windows "$SERVICEMIX_BASE"`
283 fi
284 exec $JAVA $JAVA_OPTS -Dservicemix.home="$SERVICEMIX_HOME" -Dservicemix.base="$SERVICEMIX_BASE" -Djava.util.logging.config.file=$SERVICEMIX_BASE/etc/java.util.logging.properties $OPTS -classpath "$CLASSPATH" org.apache.servicemix.kernel.main.Main $*
285}
286
287main() {
288 init
289 run $@
290}
291
292main $@