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.
18
# -----------------------------------------------------------------------------
19
# Start/Stop Script for the CATALINA Server
21
# Environment Variable Prequisites
23
# CATALINA_HOME May point at your Catalina "build" directory.
25
# CATALINA_BASE (Optional) Base directory for resolving dynamic portions
26
# of a Catalina installation. If not present, resolves to
27
# the same directory that CATALINA_HOME points to.
29
# CATALINA_OUT (Optional) Full path to a file where stdout and stderr
31
# Default is $CATALINA_BASE/logs/catalina.out
33
# CATALINA_OPTS (Optional) Java runtime options used when the "start",
34
# or "run" command is executed.
36
# CATALINA_TMPDIR (Optional) Directory path location of temporary directory
37
# the JVM should use (java.io.tmpdir). Defaults to
38
# $CATALINA_BASE/temp.
40
# JAVA_HOME Must point at your Java Development Kit installation.
41
# Required to run the with the "debug" argument.
43
# JRE_HOME Must point at your Java Development Kit installation.
44
# Defaults to JAVA_HOME if empty.
46
# JAVA_OPTS (Optional) Java runtime options used when the "start",
47
# "stop", or "run" command is executed.
49
# JPDA_TRANSPORT (Optional) JPDA transport used when the "jpda start"
50
# command is executed. The default is "dt_socket".
52
# JPDA_ADDRESS (Optional) Java runtime options used when the "jpda start"
53
# command is executed. The default is 8000.
55
# JPDA_SUSPEND (Optional) Java runtime options used when the "jpda start"
56
# command is executed. Specifies whether JVM should suspend
57
# execution immediately after startup. Default is "n".
59
# JPDA_OPTS (Optional) Java runtime options used when the "jpda start"
60
# command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
61
# and JPDA_SUSPEND are ignored. Thus, all required jpda
62
# options MUST be specified. The default is:
64
# -agentlib:jdwp=transport=$JPDA_TRANSPORT,
65
# address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND
67
# CATALINA_PID (Optional) Path of the file which should contains the pid
68
# of catalina startup java process, when start (fork) is used
70
# LOGGING_CONFIG (Optional) Override Tomcat's logging config file
71
# Example (all one line)
72
# LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
74
# LOGGING_MANAGER (Optional) Override Tomcat's logging manager
75
# Example (all one line)
76
# LOGGING_CONFIG="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
78
# $Id: catalina.sh 885002 2009-11-27 20:51:03Z markt $
79
# -----------------------------------------------------------------------------
81
# OS specific support. $var _must_ be set to either true or false.
86
CYGWIN*) cygwin=true;;
88
Darwin*) darwin=true;;
91
# resolve links - $0 may be a softlink
94
while [ -h "$PRG" ]; do
96
link=`expr "$ls" : '.*-> \(.*\)$'`
97
if expr "$link" : '/.*' > /dev/null; then
100
PRG=`dirname "$PRG"`/"$link"
104
# Get standard environment variables
105
PRGDIR=`dirname "$PRG"`
107
# Only set CATALINA_HOME if not already set
108
[ -z "$CATALINA_HOME" ] && CATALINA_HOME=`cd "$PRGDIR/.." ; pwd`
110
# Ensure that any user defined CLASSPATH variables are not used on startup,
111
# but allow them to be specified in setenv.sh, in rare case when it is needed.
114
if [ -r "$CATALINA_BASE"/bin/setenv.sh ]; then
115
. "$CATALINA_BASE"/bin/setenv.sh
116
elif [ -r "$CATALINA_HOME"/bin/setenv.sh ]; then
117
. "$CATALINA_HOME"/bin/setenv.sh
120
# For Cygwin, ensure paths are in UNIX format before anything is touched
122
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
123
[ -n "$JRE_HOME" ] && JRE_HOME=`cygpath --unix "$JRE_HOME"`
124
[ -n "$CATALINA_HOME" ] && CATALINA_HOME=`cygpath --unix "$CATALINA_HOME"`
125
[ -n "$CATALINA_BASE" ] && CATALINA_BASE=`cygpath --unix "$CATALINA_BASE"`
126
[ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
131
# Set job priority to standard for interactive (interactive - 6) by using
132
# the interactive priority - 6, the helper threads that respond to requests
133
# will be running at the same priority as interactive jobs.
134
COMMAND='chgjob job('$JOBNAME') runpty(6)'
137
# Enable multi threading
138
export QIBM_MULTI_THREADED=Y
141
# Get standard Java environment variables
143
# -r will Only work on the os400 if the files are:
144
# 1. owned by the user
145
# 2. owned by the PRIMARY group of the user
146
# this will not work if the user belongs in secondary groups
147
BASEDIR="$CATALINA_HOME"
148
. "$CATALINA_HOME"/bin/setclasspath.sh
150
if [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then
151
BASEDIR="$CATALINA_HOME"
152
. "$CATALINA_HOME"/bin/setclasspath.sh
154
echo "Cannot find $CATALINA_HOME/bin/setclasspath.sh"
155
echo "This file is needed to run this program"
160
if [ -z "$CATALINA_BASE" ] ; then
161
CATALINA_BASE="$CATALINA_HOME"
164
# Add tomcat-juli.jar and bootstrap.jar to classpath
165
# tomcat-juli.jar can be over-ridden per instance
166
if [ ! -z "$CLASSPATH" ] ; then
167
CLASSPATH="$CLASSPATH":
169
if [ "$CATALINA_BASE" != "$CATALINA_HOME" ] && [ -r "$CATALINA_BASE/bin/tomcat-juli.jar" ] ; then
170
CLASSPATH="$CLASSPATH""$CATALINA_BASE"/bin/tomcat-juli.jar:"$CATALINA_HOME"/bin/bootstrap.jar
172
CLASSPATH="$CLASSPATH""$CATALINA_HOME"/bin/bootstrap.jar
175
if [ -z "$CATALINA_OUT" ] ; then
176
CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
179
if [ -z "$CATALINA_TMPDIR" ] ; then
180
# Define the java.io.tmpdir to use for Catalina
181
CATALINA_TMPDIR="$CATALINA_BASE"/temp
184
# Bugzilla 37848: When no TTY is available, don't output to console
186
if [ "`tty`" != "not a tty" ]; then
190
# For Cygwin, switch paths to Windows format before running java
192
JAVA_HOME=`cygpath --absolute --windows "$JAVA_HOME"`
193
JRE_HOME=`cygpath --absolute --windows "$JRE_HOME"`
194
CATALINA_HOME=`cygpath --absolute --windows "$CATALINA_HOME"`
195
CATALINA_BASE=`cygpath --absolute --windows "$CATALINA_BASE"`
196
CATALINA_TMPDIR=`cygpath --absolute --windows "$CATALINA_TMPDIR"`
197
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
198
JAVA_ENDORSED_DIRS=`cygpath --path --windows "$JAVA_ENDORSED_DIRS"`
201
# Set juli LogManager config file if it is present and an override has not been issued
202
if [ -z "$LOGGING_CONFIG" ]; then
203
if [ -r "$CATALINA_BASE"/conf/logging.properties ]; then
204
LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
207
LOGGING_CONFIG="-Dnop"
211
if [ -z "$LOGGING_MANAGER" ]; then
212
JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
214
JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER"
217
# ----- Execute The Requested Command -----------------------------------------
219
# Bugzilla 37848: only output this if we have a TTY
220
if [ $have_tty -eq 1 ]; then
221
echo "Using CATALINA_BASE: $CATALINA_BASE"
222
echo "Using CATALINA_HOME: $CATALINA_HOME"
223
echo "Using CATALINA_TMPDIR: $CATALINA_TMPDIR"
224
if [ "$1" = "debug" ] ; then
225
echo "Using JAVA_HOME: $JAVA_HOME"
227
echo "Using JRE_HOME: $JRE_HOME"
229
echo "Using CLASSPATH: $CLASSPATH"
232
if [ "$1" = "jpda" ] ; then
233
if [ -z "$JPDA_TRANSPORT" ]; then
234
JPDA_TRANSPORT="dt_socket"
236
if [ -z "$JPDA_ADDRESS" ]; then
239
if [ -z "$JPDA_SUSPEND" ]; then
242
if [ -z "$JPDA_OPTS" ]; then
243
JPDA_OPTS="-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND"
245
CATALINA_OPTS="$CATALINA_OPTS $JPDA_OPTS"
249
if [ "$1" = "debug" ] ; then
251
echo "Debug command not available on OS400"
255
if [ "$1" = "-security" ] ; then
256
if [ $have_tty -eq 1 ]; then
257
echo "Using Security Manager"
260
exec "$_RUNJDB" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
261
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
262
-sourcepath "$CATALINA_HOME"/../../java \
263
-Djava.security.manager \
264
-Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
265
-Dcatalina.base="$CATALINA_BASE" \
266
-Dcatalina.home="$CATALINA_HOME" \
267
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
268
org.apache.catalina.startup.Bootstrap "$@" start
270
exec "$_RUNJDB" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
271
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
272
-sourcepath "$CATALINA_HOME"/../../java \
273
-Dcatalina.base="$CATALINA_BASE" \
274
-Dcatalina.home="$CATALINA_HOME" \
275
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
276
org.apache.catalina.startup.Bootstrap "$@" start
280
elif [ "$1" = "run" ]; then
283
if [ "$1" = "-security" ] ; then
284
if [ $have_tty -eq 1 ]; then
285
echo "Using Security Manager"
288
exec "$_RUNJAVA" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
289
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
290
-Djava.security.manager \
291
-Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
292
-Dcatalina.base="$CATALINA_BASE" \
293
-Dcatalina.home="$CATALINA_HOME" \
294
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
295
org.apache.catalina.startup.Bootstrap "$@" start
297
exec "$_RUNJAVA" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
298
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
299
-Dcatalina.base="$CATALINA_BASE" \
300
-Dcatalina.home="$CATALINA_HOME" \
301
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
302
org.apache.catalina.startup.Bootstrap "$@" start
305
elif [ "$1" = "start" ] ; then
307
if [ ! -z "$CATALINA_PID" ]; then
308
if [ -f "$CATALINA_PID" ]; then
309
echo "PID file ($CATALINA_PID) found. Is Tomcat still running? Start aborted."
315
touch "$CATALINA_OUT"
316
if [ "$1" = "-security" ] ; then
317
if [ $have_tty -eq 1 ]; then
318
echo "Using Security Manager"
321
"$_RUNJAVA" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
322
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
323
-Djava.security.manager \
324
-Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
325
-Dcatalina.base="$CATALINA_BASE" \
326
-Dcatalina.home="$CATALINA_HOME" \
327
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
328
org.apache.catalina.startup.Bootstrap "$@" start \
329
>> "$CATALINA_OUT" 2>&1 &
332
"$_RUNJAVA" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
333
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
334
-Dcatalina.base="$CATALINA_BASE" \
335
-Dcatalina.home="$CATALINA_HOME" \
336
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
337
org.apache.catalina.startup.Bootstrap "$@" start \
338
>> "$CATALINA_OUT" 2>&1 &
342
if [ ! -z "$CATALINA_PID" ]; then
343
echo $! > $CATALINA_PID
346
elif [ "$1" = "stop" ] ; then
351
if [ ! -z "$1" ]; then
352
echo $1 | grep "[^0-9]" > /dev/null 2>&1
353
if [ $? -eq 1 ]; then
360
if [ "$1" = "-force" ]; then
365
if [ ! -z "$CATALINA_PID" ]; then
366
if [ -f "$CATALINA_PID" ]; then
367
kill -0 `cat $CATALINA_PID` >/dev/null 2>&1
368
if [ $? -eq 1 ]; then
369
echo "PID file ($CATALINA_PID) found but no matching process was found. Stop aborted."
373
echo "\$CATALINA_PID was set ($CATALINA_PID) but the specified file does not exist. Is Tomcat running? Stop aborted."
378
"$_RUNJAVA" $JAVA_OPTS \
379
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
380
-Dcatalina.base="$CATALINA_BASE" \
381
-Dcatalina.home="$CATALINA_HOME" \
382
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
383
org.apache.catalina.startup.Bootstrap "$@" stop
385
if [ ! -z "$CATALINA_PID" ]; then
386
if [ -f "$CATALINA_PID" ]; then
387
while [ $SLEEP -ge 0 ]; do
388
kill -0 `cat $CATALINA_PID` >/dev/null 2>&1
389
if [ $? -eq 1 ]; then
393
if [ $SLEEP -gt 0 ]; then
396
if [ $SLEEP -eq 0 ]; then
397
if [ $FORCE -eq 0 ]; then
398
echo "Tomcat did not stop in time. PID file was not removed."
401
SLEEP=`expr $SLEEP - 1 `
406
if [ $FORCE -eq 1 ]; then
407
if [ -z "$CATALINA_PID" ]; then
408
echo "Kill failed: \$CATALINA_PID not set"
410
if [ -f "$CATALINA_PID" ]; then
411
echo "Killing: `cat $CATALINA_PID`"
412
kill -9 `cat $CATALINA_PID`
418
elif [ "$1" = "version" ] ; then
421
-classpath "$CATALINA_HOME/lib/catalina.jar" \
422
org.apache.catalina.util.ServerInfo
426
echo "Usage: catalina.sh ( commands ... )"
429
echo " debug Start Catalina in a debugger (not available on OS400)"
430
echo " debug -security Debug Catalina with a security manager (not available on OS400)"
432
echo " debug Start Catalina in a debugger"
433
echo " debug -security Debug Catalina with a security manager"
435
echo " jpda start Start Catalina under JPDA debugger"
436
echo " run Start Catalina in the current window"
437
echo " run -security Start in the current window with security manager"
438
echo " start Start Catalina in a separate window"
439
echo " start -security Start in a separate window with security manager"
440
echo " stop Stop Catalina, waiting up to 5 seconds for the process to end"
441
echo " stop n Stop Catalina, waiting up to n seconds for the process to end"
442
echo " stop -force Stop Catalina, wait up to 5 seconds and then use kill -KILL if still running"
443
echo " stop n -force Stop Catalina, wait up to n seconds and then use kill -KILL if still running"
444
echo " version What version of tomcat are you running?"
445
echo "Note: Waiting for the process to end and use of the -force option require that \$CATALINA_PID is defined"