blob: 33a4803dffa4f9ebdc87f5570abb01b4dd59ef00 [file] [log] [blame]
Hongqing Liufd5ee812014-05-10 16:32:51 +08001#!/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# -----------------------------------------------------------------------------
刘洪青6266f992017-05-15 21:21:03 +080019# Control Script for the CATALINA Server
Hongqing Liufd5ee812014-05-10 16:32:51 +080020#
21# Environment Variable Prerequisites
22#
刘洪青6266f992017-05-15 21:21:03 +080023# Do not set the variables in this script. Instead put them into a script
24# setenv.sh in CATALINA_BASE/bin to keep your customizations separate.
25#
Hongqing Liufd5ee812014-05-10 16:32:51 +080026# CATALINA_HOME May point at your Catalina "build" directory.
27#
28# CATALINA_BASE (Optional) Base directory for resolving dynamic portions
29# of a Catalina installation. If not present, resolves to
30# the same directory that CATALINA_HOME points to.
31#
32# CATALINA_OUT (Optional) Full path to a file where stdout and stderr
33# will be redirected.
34# Default is $CATALINA_BASE/logs/catalina.out
35#
36# CATALINA_OPTS (Optional) Java runtime options used when the "start",
刘洪青6266f992017-05-15 21:21:03 +080037# "run" or "debug" command is executed.
38# Include here and not in JAVA_OPTS all options, that should
39# only be used by Tomcat itself, not by the stop process,
40# the version command etc.
41# Examples are heap size, GC logging, JMX ports etc.
Hongqing Liufd5ee812014-05-10 16:32:51 +080042#
43# CATALINA_TMPDIR (Optional) Directory path location of temporary directory
44# the JVM should use (java.io.tmpdir). Defaults to
45# $CATALINA_BASE/temp.
46#
47# JAVA_HOME Must point at your Java Development Kit installation.
48# Required to run the with the "debug" argument.
49#
刘洪青6266f992017-05-15 21:21:03 +080050# JRE_HOME Must point at your Java Runtime installation.
51# Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME
52# are both set, JRE_HOME is used.
Hongqing Liufd5ee812014-05-10 16:32:51 +080053#
刘洪青6266f992017-05-15 21:21:03 +080054# JAVA_OPTS (Optional) Java runtime options used when any command
55# is executed.
56# Include here and not in CATALINA_OPTS all options, that
57# should be used by Tomcat and also by the stop process,
58# the version command etc.
59# Most options should go into CATALINA_OPTS.
Hongqing Liufd5ee812014-05-10 16:32:51 +080060#
61# JAVA_ENDORSED_DIRS (Optional) Lists of of colon separated directories
62# containing some jars in order to allow replacement of APIs
63# created outside of the JCP (i.e. DOM and SAX from W3C).
64# It can also be used to update the XML parser implementation.
65# Defaults to $CATALINA_HOME/endorsed.
66#
67# JPDA_TRANSPORT (Optional) JPDA transport used when the "jpda start"
68# command is executed. The default is "dt_socket".
69#
70# JPDA_ADDRESS (Optional) Java runtime options used when the "jpda start"
71# command is executed. The default is 8000.
72#
73# JPDA_SUSPEND (Optional) Java runtime options used when the "jpda start"
74# command is executed. Specifies whether JVM should suspend
75# execution immediately after startup. Default is "n".
76#
77# JPDA_OPTS (Optional) Java runtime options used when the "jpda start"
78# command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
79# and JPDA_SUSPEND are ignored. Thus, all required jpda
80# options MUST be specified. The default is:
81#
82# -agentlib:jdwp=transport=$JPDA_TRANSPORT,
83# address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND
84#
刘洪青6266f992017-05-15 21:21:03 +080085# JSSE_OPTS (Optional) Java runtime options used to control the TLS
86# implementation when JSSE is used. Default is:
87# "-Djdk.tls.ephemeralDHKeySize=2048"
88#
Hongqing Liufd5ee812014-05-10 16:32:51 +080089# CATALINA_PID (Optional) Path of the file which should contains the pid
刘洪青6266f992017-05-15 21:21:03 +080090# of the catalina startup java process, when start (fork) is
91# used
Hongqing Liufd5ee812014-05-10 16:32:51 +080092#
93# LOGGING_CONFIG (Optional) Override Tomcat's logging config file
94# Example (all one line)
95# LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
96#
97# LOGGING_MANAGER (Optional) Override Tomcat's logging manager
98# Example (all one line)
99# LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
刘洪青6266f992017-05-15 21:21:03 +0800100#
101# USE_NOHUP (Optional) If set to the string true the start command will
102# use nohup so that the Tomcat process will ignore any hangup
103# signals. Default is "false" unless running on HP-UX in which
104# case the default is "true"
Hongqing Liufd5ee812014-05-10 16:32:51 +0800105# -----------------------------------------------------------------------------
106
107# OS specific support. $var _must_ be set to either true or false.
108cygwin=false
Hongqing Liufd5ee812014-05-10 16:32:51 +0800109darwin=false
刘洪青6266f992017-05-15 21:21:03 +0800110os400=false
111hpux=false
Hongqing Liufd5ee812014-05-10 16:32:51 +0800112case "`uname`" in
113CYGWIN*) cygwin=true;;
Hongqing Liufd5ee812014-05-10 16:32:51 +0800114Darwin*) darwin=true;;
刘洪青6266f992017-05-15 21:21:03 +0800115OS400*) os400=true;;
116HP-UX*) hpux=true;;
Hongqing Liufd5ee812014-05-10 16:32:51 +0800117esac
118
119# resolve links - $0 may be a softlink
120PRG="$0"
121
122while [ -h "$PRG" ]; do
123 ls=`ls -ld "$PRG"`
124 link=`expr "$ls" : '.*-> \(.*\)$'`
125 if expr "$link" : '/.*' > /dev/null; then
126 PRG="$link"
127 else
128 PRG=`dirname "$PRG"`/"$link"
129 fi
130done
131
132# Get standard environment variables
133PRGDIR=`dirname "$PRG"`
134
135# Only set CATALINA_HOME if not already set
136[ -z "$CATALINA_HOME" ] && CATALINA_HOME=`cd "$PRGDIR/.." >/dev/null; pwd`
137
138# Copy CATALINA_BASE from CATALINA_HOME if not already set
139[ -z "$CATALINA_BASE" ] && CATALINA_BASE="$CATALINA_HOME"
140
141# Ensure that any user defined CLASSPATH variables are not used on startup,
142# but allow them to be specified in setenv.sh, in rare case when it is needed.
143CLASSPATH=
144
145if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
146 . "$CATALINA_BASE/bin/setenv.sh"
147elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
148 . "$CATALINA_HOME/bin/setenv.sh"
149fi
150
151# For Cygwin, ensure paths are in UNIX format before anything is touched
152if $cygwin; then
153 [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
154 [ -n "$JRE_HOME" ] && JRE_HOME=`cygpath --unix "$JRE_HOME"`
155 [ -n "$CATALINA_HOME" ] && CATALINA_HOME=`cygpath --unix "$CATALINA_HOME"`
156 [ -n "$CATALINA_BASE" ] && CATALINA_BASE=`cygpath --unix "$CATALINA_BASE"`
157 [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
158fi
159
160# For OS400
161if $os400; then
162 # Set job priority to standard for interactive (interactive - 6) by using
163 # the interactive priority - 6, the helper threads that respond to requests
164 # will be running at the same priority as interactive jobs.
165 COMMAND='chgjob job('$JOBNAME') runpty(6)'
166 system $COMMAND
167
168 # Enable multi threading
169 export QIBM_MULTI_THREADED=Y
170fi
171
172# Get standard Java environment variables
173if $os400; then
174 # -r will Only work on the os400 if the files are:
175 # 1. owned by the user
176 # 2. owned by the PRIMARY group of the user
177 # this will not work if the user belongs in secondary groups
Hongqing Liufd5ee812014-05-10 16:32:51 +0800178 . "$CATALINA_HOME"/bin/setclasspath.sh
179else
180 if [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then
Hongqing Liufd5ee812014-05-10 16:32:51 +0800181 . "$CATALINA_HOME"/bin/setclasspath.sh
182 else
183 echo "Cannot find $CATALINA_HOME/bin/setclasspath.sh"
184 echo "This file is needed to run this program"
185 exit 1
186 fi
187fi
188
刘洪青6266f992017-05-15 21:21:03 +0800189# Add on extra jar files to CLASSPATH
Hongqing Liufd5ee812014-05-10 16:32:51 +0800190if [ ! -z "$CLASSPATH" ] ; then
191 CLASSPATH="$CLASSPATH":
192fi
刘洪青6266f992017-05-15 21:21:03 +0800193CLASSPATH="$CLASSPATH""$CATALINA_HOME"/bin/bootstrap.jar
Hongqing Liufd5ee812014-05-10 16:32:51 +0800194
195if [ -z "$CATALINA_OUT" ] ; then
196 CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
197fi
198
199if [ -z "$CATALINA_TMPDIR" ] ; then
200 # Define the java.io.tmpdir to use for Catalina
201 CATALINA_TMPDIR="$CATALINA_BASE"/temp
202fi
203
刘洪青6266f992017-05-15 21:21:03 +0800204# Add tomcat-juli.jar to classpath
205# tomcat-juli.jar can be over-ridden per instance
206if [ -r "$CATALINA_BASE/bin/tomcat-juli.jar" ] ; then
207 CLASSPATH=$CLASSPATH:$CATALINA_BASE/bin/tomcat-juli.jar
208else
209 CLASSPATH=$CLASSPATH:$CATALINA_HOME/bin/tomcat-juli.jar
210fi
211
Hongqing Liufd5ee812014-05-10 16:32:51 +0800212# Bugzilla 37848: When no TTY is available, don't output to console
213have_tty=0
214if [ "`tty`" != "not a tty" ]; then
215 have_tty=1
216fi
217
218# For Cygwin, switch paths to Windows format before running java
219if $cygwin; then
220 JAVA_HOME=`cygpath --absolute --windows "$JAVA_HOME"`
221 JRE_HOME=`cygpath --absolute --windows "$JRE_HOME"`
222 CATALINA_HOME=`cygpath --absolute --windows "$CATALINA_HOME"`
223 CATALINA_BASE=`cygpath --absolute --windows "$CATALINA_BASE"`
224 CATALINA_TMPDIR=`cygpath --absolute --windows "$CATALINA_TMPDIR"`
225 CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
226 JAVA_ENDORSED_DIRS=`cygpath --path --windows "$JAVA_ENDORSED_DIRS"`
227fi
228
刘洪青6266f992017-05-15 21:21:03 +0800229if [ -z "$JSSE_OPTS" ] ; then
230 JSSE_OPTS="-Djdk.tls.ephemeralDHKeySize=2048"
231fi
232JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS"
233
Hongqing Liufd5ee812014-05-10 16:32:51 +0800234# Set juli LogManager config file if it is present and an override has not been issued
235if [ -z "$LOGGING_CONFIG" ]; then
236 if [ -r "$CATALINA_BASE"/conf/logging.properties ]; then
237 LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
238 else
239 # Bugzilla 45585
240 LOGGING_CONFIG="-Dnop"
241 fi
242fi
243
244if [ -z "$LOGGING_MANAGER" ]; then
245 LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
246fi
247
刘洪青6266f992017-05-15 21:21:03 +0800248# Uncomment the following line to make the umask available when using the
249# org.apache.catalina.security.SecurityListener
250#JAVA_OPTS="$JAVA_OPTS -Dorg.apache.catalina.security.SecurityListener.UMASK=`umask`"
251
252if [ -z "$USE_NOHUP" ]; then
253 if $hpux; then
254 USE_NOHUP="true"
255 else
256 USE_NOHUP="false"
257 fi
258fi
259unset _NOHUP
260if [ "$USE_NOHUP" = "true" ]; then
261 _NOHUP=nohup
262fi
263
Hongqing Liufd5ee812014-05-10 16:32:51 +0800264# ----- Execute The Requested Command -----------------------------------------
265
266# Bugzilla 37848: only output this if we have a TTY
267if [ $have_tty -eq 1 ]; then
268 echo "Using CATALINA_BASE: $CATALINA_BASE"
269 echo "Using CATALINA_HOME: $CATALINA_HOME"
270 echo "Using CATALINA_TMPDIR: $CATALINA_TMPDIR"
271 if [ "$1" = "debug" ] ; then
272 echo "Using JAVA_HOME: $JAVA_HOME"
273 else
274 echo "Using JRE_HOME: $JRE_HOME"
275 fi
276 echo "Using CLASSPATH: $CLASSPATH"
277 if [ ! -z "$CATALINA_PID" ]; then
278 echo "Using CATALINA_PID: $CATALINA_PID"
279 fi
280fi
281
282if [ "$1" = "jpda" ] ; then
283 if [ -z "$JPDA_TRANSPORT" ]; then
284 JPDA_TRANSPORT="dt_socket"
285 fi
286 if [ -z "$JPDA_ADDRESS" ]; then
287 JPDA_ADDRESS="8000"
288 fi
289 if [ -z "$JPDA_SUSPEND" ]; then
290 JPDA_SUSPEND="n"
291 fi
292 if [ -z "$JPDA_OPTS" ]; then
293 JPDA_OPTS="-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND"
294 fi
刘洪青6266f992017-05-15 21:21:03 +0800295 CATALINA_OPTS="$JPDA_OPTS $CATALINA_OPTS"
Hongqing Liufd5ee812014-05-10 16:32:51 +0800296 shift
297fi
298
299if [ "$1" = "debug" ] ; then
300 if $os400; then
301 echo "Debug command not available on OS400"
302 exit 1
303 else
304 shift
305 if [ "$1" = "-security" ] ; then
306 if [ $have_tty -eq 1 ]; then
307 echo "Using Security Manager"
308 fi
309 shift
310 exec "$_RUNJDB" "$LOGGING_CONFIG" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
311 -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
312 -sourcepath "$CATALINA_HOME"/../../java \
313 -Djava.security.manager \
314 -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
315 -Dcatalina.base="$CATALINA_BASE" \
316 -Dcatalina.home="$CATALINA_HOME" \
317 -Djava.io.tmpdir="$CATALINA_TMPDIR" \
318 org.apache.catalina.startup.Bootstrap "$@" start
319 else
320 exec "$_RUNJDB" "$LOGGING_CONFIG" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
321 -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
322 -sourcepath "$CATALINA_HOME"/../../java \
323 -Dcatalina.base="$CATALINA_BASE" \
324 -Dcatalina.home="$CATALINA_HOME" \
325 -Djava.io.tmpdir="$CATALINA_TMPDIR" \
326 org.apache.catalina.startup.Bootstrap "$@" start
327 fi
328 fi
329
330elif [ "$1" = "run" ]; then
331
332 shift
333 if [ "$1" = "-security" ] ; then
334 if [ $have_tty -eq 1 ]; then
335 echo "Using Security Manager"
336 fi
337 shift
刘洪青6266f992017-05-15 21:21:03 +0800338 eval exec "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
339 -Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \
Hongqing Liufd5ee812014-05-10 16:32:51 +0800340 -Djava.security.manager \
刘洪青6266f992017-05-15 21:21:03 +0800341 -Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \
342 -Dcatalina.base="\"$CATALINA_BASE\"" \
343 -Dcatalina.home="\"$CATALINA_HOME\"" \
344 -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
Hongqing Liufd5ee812014-05-10 16:32:51 +0800345 org.apache.catalina.startup.Bootstrap "$@" start
346 else
刘洪青6266f992017-05-15 21:21:03 +0800347 eval exec "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
348 -Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \
349 -Dcatalina.base="\"$CATALINA_BASE\"" \
350 -Dcatalina.home="\"$CATALINA_HOME\"" \
351 -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
Hongqing Liufd5ee812014-05-10 16:32:51 +0800352 org.apache.catalina.startup.Bootstrap "$@" start
353 fi
354
355elif [ "$1" = "start" ] ; then
356
357 if [ ! -z "$CATALINA_PID" ]; then
358 if [ -f "$CATALINA_PID" ]; then
359 if [ -s "$CATALINA_PID" ]; then
360 echo "Existing PID file found during start."
361 if [ -r "$CATALINA_PID" ]; then
362 PID=`cat "$CATALINA_PID"`
363 ps -p $PID >/dev/null 2>&1
364 if [ $? -eq 0 ] ; then
365 echo "Tomcat appears to still be running with PID $PID. Start aborted."
刘洪青6266f992017-05-15 21:21:03 +0800366 echo "If the following process is not a Tomcat process, remove the PID file and try again:"
367 ps -f -p $PID
Hongqing Liufd5ee812014-05-10 16:32:51 +0800368 exit 1
369 else
370 echo "Removing/clearing stale PID file."
371 rm -f "$CATALINA_PID" >/dev/null 2>&1
372 if [ $? != 0 ]; then
373 if [ -w "$CATALINA_PID" ]; then
374 cat /dev/null > "$CATALINA_PID"
375 else
376 echo "Unable to remove or clear stale PID file. Start aborted."
377 exit 1
378 fi
379 fi
380 fi
381 else
382 echo "Unable to read PID file. Start aborted."
383 exit 1
384 fi
385 else
386 rm -f "$CATALINA_PID" >/dev/null 2>&1
387 if [ $? != 0 ]; then
388 if [ ! -w "$CATALINA_PID" ]; then
389 echo "Unable to remove or write to empty PID file. Start aborted."
390 exit 1
391 fi
392 fi
393 fi
394 fi
395 fi
396
397 shift
398 touch "$CATALINA_OUT"
399 if [ "$1" = "-security" ] ; then
400 if [ $have_tty -eq 1 ]; then
401 echo "Using Security Manager"
402 fi
403 shift
刘洪青6266f992017-05-15 21:21:03 +0800404 eval $_NOHUP "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
405 -Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \
Hongqing Liufd5ee812014-05-10 16:32:51 +0800406 -Djava.security.manager \
刘洪青6266f992017-05-15 21:21:03 +0800407 -Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \
408 -Dcatalina.base="\"$CATALINA_BASE\"" \
409 -Dcatalina.home="\"$CATALINA_HOME\"" \
410 -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
Hongqing Liufd5ee812014-05-10 16:32:51 +0800411 org.apache.catalina.startup.Bootstrap "$@" start \
刘洪青6266f992017-05-15 21:21:03 +0800412 >> "$CATALINA_OUT" 2>&1 "&"
Hongqing Liufd5ee812014-05-10 16:32:51 +0800413
414 else
刘洪青6266f992017-05-15 21:21:03 +0800415 eval $_NOHUP "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
416 -Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \
417 -Dcatalina.base="\"$CATALINA_BASE\"" \
418 -Dcatalina.home="\"$CATALINA_HOME\"" \
419 -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
Hongqing Liufd5ee812014-05-10 16:32:51 +0800420 org.apache.catalina.startup.Bootstrap "$@" start \
刘洪青6266f992017-05-15 21:21:03 +0800421 >> "$CATALINA_OUT" 2>&1 "&"
Hongqing Liufd5ee812014-05-10 16:32:51 +0800422
423 fi
424
425 if [ ! -z "$CATALINA_PID" ]; then
426 echo $! > "$CATALINA_PID"
427 fi
428
刘洪青6266f992017-05-15 21:21:03 +0800429 echo "Tomcat started."
430
Hongqing Liufd5ee812014-05-10 16:32:51 +0800431elif [ "$1" = "stop" ] ; then
432
433 shift
434
435 SLEEP=5
436 if [ ! -z "$1" ]; then
437 echo $1 | grep "[^0-9]" >/dev/null 2>&1
438 if [ $? -gt 0 ]; then
439 SLEEP=$1
440 shift
441 fi
442 fi
443
444 FORCE=0
445 if [ "$1" = "-force" ]; then
446 shift
447 FORCE=1
448 fi
449
450 if [ ! -z "$CATALINA_PID" ]; then
451 if [ -f "$CATALINA_PID" ]; then
452 if [ -s "$CATALINA_PID" ]; then
453 kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1
454 if [ $? -gt 0 ]; then
455 echo "PID file found but no matching process was found. Stop aborted."
456 exit 1
457 fi
458 else
459 echo "PID file is empty and has been ignored."
460 fi
461 else
462 echo "\$CATALINA_PID was set but the specified file does not exist. Is Tomcat running? Stop aborted."
463 exit 1
464 fi
465 fi
刘洪青6266f992017-05-15 21:21:03 +0800466
467 eval "\"$_RUNJAVA\"" $LOGGING_MANAGER $JAVA_OPTS \
468 -Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \
469 -Dcatalina.base="\"$CATALINA_BASE\"" \
470 -Dcatalina.home="\"$CATALINA_HOME\"" \
471 -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
Hongqing Liufd5ee812014-05-10 16:32:51 +0800472 org.apache.catalina.startup.Bootstrap "$@" stop
473
刘洪青6266f992017-05-15 21:21:03 +0800474 # stop failed. Shutdown port disabled? Try a normal kill.
475 if [ $? != 0 ]; then
476 if [ ! -z "$CATALINA_PID" ]; then
477 echo "The stop command failed. Attempting to signal the process to stop through OS signal."
478 kill -15 `cat "$CATALINA_PID"` >/dev/null 2>&1
479 fi
480 fi
481
Hongqing Liufd5ee812014-05-10 16:32:51 +0800482 if [ ! -z "$CATALINA_PID" ]; then
483 if [ -f "$CATALINA_PID" ]; then
484 while [ $SLEEP -ge 0 ]; do
485 kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1
486 if [ $? -gt 0 ]; then
487 rm -f "$CATALINA_PID" >/dev/null 2>&1
488 if [ $? != 0 ]; then
489 if [ -w "$CATALINA_PID" ]; then
490 cat /dev/null > "$CATALINA_PID"
刘洪青6266f992017-05-15 21:21:03 +0800491 # If Tomcat has stopped don't try and force a stop with an empty PID file
492 FORCE=0
Hongqing Liufd5ee812014-05-10 16:32:51 +0800493 else
刘洪青6266f992017-05-15 21:21:03 +0800494 echo "The PID file could not be removed or cleared."
Hongqing Liufd5ee812014-05-10 16:32:51 +0800495 fi
496 fi
刘洪青6266f992017-05-15 21:21:03 +0800497 echo "Tomcat stopped."
Hongqing Liufd5ee812014-05-10 16:32:51 +0800498 break
499 fi
500 if [ $SLEEP -gt 0 ]; then
501 sleep 1
502 fi
503 if [ $SLEEP -eq 0 ]; then
刘洪青6266f992017-05-15 21:21:03 +0800504 echo "Tomcat did not stop in time."
Hongqing Liufd5ee812014-05-10 16:32:51 +0800505 if [ $FORCE -eq 0 ]; then
刘洪青6266f992017-05-15 21:21:03 +0800506 echo "PID file was not removed."
Hongqing Liufd5ee812014-05-10 16:32:51 +0800507 fi
刘洪青6266f992017-05-15 21:21:03 +0800508 echo "To aid diagnostics a thread dump has been written to standard out."
509 kill -3 `cat "$CATALINA_PID"`
Hongqing Liufd5ee812014-05-10 16:32:51 +0800510 fi
511 SLEEP=`expr $SLEEP - 1 `
512 done
513 fi
514 fi
515
刘洪青6266f992017-05-15 21:21:03 +0800516 KILL_SLEEP_INTERVAL=5
Hongqing Liufd5ee812014-05-10 16:32:51 +0800517 if [ $FORCE -eq 1 ]; then
518 if [ -z "$CATALINA_PID" ]; then
519 echo "Kill failed: \$CATALINA_PID not set"
520 else
521 if [ -f "$CATALINA_PID" ]; then
522 PID=`cat "$CATALINA_PID"`
523 echo "Killing Tomcat with the PID: $PID"
524 kill -9 $PID
刘洪青6266f992017-05-15 21:21:03 +0800525 while [ $KILL_SLEEP_INTERVAL -ge 0 ]; do
526 kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1
527 if [ $? -gt 0 ]; then
528 rm -f "$CATALINA_PID" >/dev/null 2>&1
529 if [ $? != 0 ]; then
530 if [ -w "$CATALINA_PID" ]; then
531 cat /dev/null > "$CATALINA_PID"
532 else
533 echo "The PID file could not be removed."
534 fi
535 fi
536 echo "The Tomcat process has been killed."
537 break
538 fi
539 if [ $KILL_SLEEP_INTERVAL -gt 0 ]; then
540 sleep 1
541 fi
542 KILL_SLEEP_INTERVAL=`expr $KILL_SLEEP_INTERVAL - 1 `
543 done
544 if [ $KILL_SLEEP_INTERVAL -lt 0 ]; then
545 echo "Tomcat has not been killed completely yet. The process might be waiting on some system call or might be UNINTERRUPTIBLE."
Hongqing Liufd5ee812014-05-10 16:32:51 +0800546 fi
547 fi
548 fi
549 fi
550
刘洪青6266f992017-05-15 21:21:03 +0800551elif [ "$1" = "configtest" ] ; then
552
553 eval "\"$_RUNJAVA\"" $LOGGING_MANAGER $JAVA_OPTS \
554 -Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \
555 -Dcatalina.base="\"$CATALINA_BASE\"" \
556 -Dcatalina.home="\"$CATALINA_HOME\"" \
557 -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
558 org.apache.catalina.startup.Bootstrap configtest
559 result=$?
560 if [ $result -ne 0 ]; then
561 echo "Configuration error detected!"
562 fi
563 exit $result
564
Hongqing Liufd5ee812014-05-10 16:32:51 +0800565elif [ "$1" = "version" ] ; then
566
567 "$_RUNJAVA" \
568 -classpath "$CATALINA_HOME/lib/catalina.jar" \
569 org.apache.catalina.util.ServerInfo
570
571else
572
573 echo "Usage: catalina.sh ( commands ... )"
574 echo "commands:"
575 if $os400; then
576 echo " debug Start Catalina in a debugger (not available on OS400)"
577 echo " debug -security Debug Catalina with a security manager (not available on OS400)"
578 else
579 echo " debug Start Catalina in a debugger"
580 echo " debug -security Debug Catalina with a security manager"
581 fi
582 echo " jpda start Start Catalina under JPDA debugger"
583 echo " run Start Catalina in the current window"
584 echo " run -security Start in the current window with security manager"
585 echo " start Start Catalina in a separate window"
586 echo " start -security Start in a separate window with security manager"
587 echo " stop Stop Catalina, waiting up to 5 seconds for the process to end"
588 echo " stop n Stop Catalina, waiting up to n seconds for the process to end"
589 echo " stop -force Stop Catalina, wait up to 5 seconds and then use kill -KILL if still running"
590 echo " stop n -force Stop Catalina, wait up to n seconds and then use kill -KILL if still running"
刘洪青6266f992017-05-15 21:21:03 +0800591 echo " configtest Run a basic syntax check on server.xml - check exit code for result"
Hongqing Liufd5ee812014-05-10 16:32:51 +0800592 echo " version What version of tomcat are you running?"
593 echo "Note: Waiting for the process to end and use of the -force option require that \$CATALINA_PID is defined"
594 exit 1
595
596fi