Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
771 blopes 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
# -----------------------------------------------------------------------------
19
# Control Script for the CATALINA Server
20
#
21
# For supported commands call "catalina.sh help" or see the usage section at
22
# the end of this file.
23
#
24
# Environment Variable Prerequisites
25
#
26
#   Do not set the variables in this script. Instead put them into a script
27
#   setenv.sh in CATALINA_BASE/bin to keep your customizations separate.
28
#
29
#   CATALINA_HOME   May point at your Catalina "build" directory.
30
#
31
#   CATALINA_BASE   (Optional) Base directory for resolving dynamic portions
32
#                   of a Catalina installation.  If not present, resolves to
33
#                   the same directory that CATALINA_HOME points to.
34
#
35
#   CATALINA_OUT    (Optional) Full path to a file where stdout and stderr
36
#                   will be redirected.
37
#                   Default is $CATALINA_BASE/logs/catalina.out
38
#
39
#   CATALINA_OUT_CMD (Optional) Command which will be executed and receive
40
#                   as its stdin the stdout and stderr from the Tomcat java
41
#                   process. If CATALINA_OUT_CMD is set, the value of
42
#                   CATALINA_OUT will be used as a named pipe.
43
#                   No default.
44
#                   Example (all one line)
45
#                   CATALINA_OUT_CMD="/usr/bin/rotatelogs -f $CATALINA_BASE/logs/catalina.out.%Y-%m-%d.log 86400"
46
#
47
#   CATALINA_OPTS   (Optional) Java runtime options used when the "start",
48
#                   "run" or "debug" command is executed.
49
#                   Include here and not in JAVA_OPTS all options, that should
50
#                   only be used by Tomcat itself, not by the stop process,
51
#                   the version command etc.
52
#                   Examples are heap size, GC logging, JMX ports etc.
53
#
54
#   CATALINA_TMPDIR (Optional) Directory path location of temporary directory
55
#                   the JVM should use (java.io.tmpdir).  Defaults to
56
#                   $CATALINA_BASE/temp.
57
#
58
#   JAVA_HOME       Must point at your Java Development Kit installation.
59
#                   Required to run the with the "debug" argument.
60
#
61
#   JRE_HOME        Must point at your Java Runtime installation.
62
#                   Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME
63
#                   are both set, JRE_HOME is used.
64
#
65
#   JAVA_OPTS       (Optional) Java runtime options used when any command
66
#                   is executed.
67
#                   Include here and not in CATALINA_OPTS all options, that
68
#                   should be used by Tomcat and also by the stop process,
69
#                   the version command etc.
70
#                   Most options should go into CATALINA_OPTS.
71
#
72
#   JAVA_ENDORSED_DIRS (Optional) Lists of of colon separated directories
73
#                   containing some jars in order to allow replacement of APIs
74
#                   created outside of the JCP (i.e. DOM and SAX from W3C).
75
#                   It can also be used to update the XML parser implementation.
76
#                   This is only supported for Java <= 8.
77
#                   Defaults to $CATALINA_HOME/endorsed.
78
#
79
#   JPDA_TRANSPORT  (Optional) JPDA transport used when the "jpda start"
80
#                   command is executed. The default is "dt_socket".
81
#
82
#   JPDA_ADDRESS    (Optional) Java runtime options used when the "jpda start"
83
#                   command is executed. The default is localhost:8000.
84
#
85
#   JPDA_SUSPEND    (Optional) Java runtime options used when the "jpda start"
86
#                   command is executed. Specifies whether JVM should suspend
87
#                   execution immediately after startup. Default is "n".
88
#
89
#   JPDA_OPTS       (Optional) Java runtime options used when the "jpda start"
90
#                   command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
91
#                   and JPDA_SUSPEND are ignored. Thus, all required jpda
92
#                   options MUST be specified. The default is:
93
#
94
#                   -agentlib:jdwp=transport=$JPDA_TRANSPORT,
95
#                       address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND
96
#
97
#   JSSE_OPTS       (Optional) Java runtime options used to control the TLS
98
#                   implementation when JSSE is used. Default is:
99
#                   "-Djdk.tls.ephemeralDHKeySize=2048"
100
#
101
#   CATALINA_PID    (Optional) Path of the file which should contains the pid
102
#                   of the catalina startup java process, when start (fork) is
103
#                   used
104
#
105
#   CATALINA_LOGGING_CONFIG (Optional) Override Tomcat's logging config file
106
#                   Example (all one line)
107
#                   CATALINA_LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
108
#
109
#   LOGGING_CONFIG  Deprecated
110
#                   Use CATALINA_LOGGING_CONFIG
111
#                   This is only used if CATALINA_LOGGING_CONFIG is not set
112
#                   and LOGGING_CONFIG starts with "-D..."
113
#
114
#   LOGGING_MANAGER (Optional) Override Tomcat's logging manager
115
#                   Example (all one line)
116
#                   LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
117
#
118
#   UMASK           (Optional) Override Tomcat's default UMASK of 0027
119
#
120
#   USE_NOHUP       (Optional) If set to the string true the start command will
121
#                   use nohup so that the Tomcat process will ignore any hangup
122
#                   signals. Default is "false" unless running on HP-UX in which
123
#                   case the default is "true"
124
# -----------------------------------------------------------------------------
125
 
126
# OS specific support.  $var _must_ be set to either true or false.
127
cygwin=false
128
darwin=false
129
os400=false
130
hpux=false
131
case "`uname`" in
132
CYGWIN*) cygwin=true;;
133
Darwin*) darwin=true;;
134
OS400*) os400=true;;
135
HP-UX*) hpux=true;;
136
esac
137
 
138
# resolve links - $0 may be a softlink
139
PRG="$0"
140
 
141
while [ -h "$PRG" ]; do
142
  ls=`ls -ld "$PRG"`
143
  link=`expr "$ls" : '.*-> \(.*\)$'`
144
  if expr "$link" : '/.*' > /dev/null; then
145
    PRG="$link"
146
  else
147
    PRG=`dirname "$PRG"`/"$link"
148
  fi
149
done
150
 
151
# Get standard environment variables
152
PRGDIR=`dirname "$PRG"`
153
 
154
# Only set CATALINA_HOME if not already set
155
[ -z "$CATALINA_HOME" ] && CATALINA_HOME=`cd "$PRGDIR/.." >/dev/null; pwd`
156
 
157
# Copy CATALINA_BASE from CATALINA_HOME if not already set
158
[ -z "$CATALINA_BASE" ] && CATALINA_BASE="$CATALINA_HOME"
159
 
160
# Ensure that any user defined CLASSPATH variables are not used on startup,
161
# but allow them to be specified in setenv.sh, in rare case when it is needed.
162
CLASSPATH=
163
 
164
if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
165
  . "$CATALINA_BASE/bin/setenv.sh"
166
elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
167
  . "$CATALINA_HOME/bin/setenv.sh"
168
fi
169
 
170
# For Cygwin, ensure paths are in UNIX format before anything is touched
171
if $cygwin; then
172
  [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
173
  [ -n "$JRE_HOME" ] && JRE_HOME=`cygpath --unix "$JRE_HOME"`
174
  [ -n "$CATALINA_HOME" ] && CATALINA_HOME=`cygpath --unix "$CATALINA_HOME"`
175
  [ -n "$CATALINA_BASE" ] && CATALINA_BASE=`cygpath --unix "$CATALINA_BASE"`
176
  [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
177
fi
178
 
179
# Ensure that neither CATALINA_HOME nor CATALINA_BASE contains a colon
180
# as this is used as the separator in the classpath and Java provides no
181
# mechanism for escaping if the same character appears in the path.
182
case $CATALINA_HOME in
183
  *:*) echo "Using CATALINA_HOME:   $CATALINA_HOME";
184
       echo "Unable to start as CATALINA_HOME contains a colon (:) character";
185
       exit 1;
186
esac
187
case $CATALINA_BASE in
188
  *:*) echo "Using CATALINA_BASE:   $CATALINA_BASE";
189
       echo "Unable to start as CATALINA_BASE contains a colon (:) character";
190
       exit 1;
191
esac
192
 
193
# For OS400
194
if $os400; then
195
  # Set job priority to standard for interactive (interactive - 6) by using
196
  # the interactive priority - 6, the helper threads that respond to requests
197
  # will be running at the same priority as interactive jobs.
198
  COMMAND='chgjob job('$JOBNAME') runpty(6)'
199
  system $COMMAND
200
 
201
  # Enable multi threading
202
  export QIBM_MULTI_THREADED=Y
203
fi
204
 
205
# Get standard Java environment variables
206
if $os400; then
207
  # -r will Only work on the os400 if the files are:
208
  # 1. owned by the user
209
  # 2. owned by the PRIMARY group of the user
210
  # this will not work if the user belongs in secondary groups
211
  . "$CATALINA_HOME"/bin/setclasspath.sh
212
else
213
  if [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then
214
    . "$CATALINA_HOME"/bin/setclasspath.sh
215
  else
216
    echo "Cannot find $CATALINA_HOME/bin/setclasspath.sh"
217
    echo "This file is needed to run this program"
218
    exit 1
219
  fi
220
fi
221
 
222
# Add on extra jar files to CLASSPATH
223
if [ ! -z "$CLASSPATH" ] ; then
224
  CLASSPATH="$CLASSPATH":
225
fi
226
CLASSPATH="$CLASSPATH""$CATALINA_HOME"/bin/bootstrap.jar
227
 
228
if [ -z "$CATALINA_OUT" ] ; then
229
  CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
230
fi
231
 
232
if [ -z "$CATALINA_TMPDIR" ] ; then
233
  # Define the java.io.tmpdir to use for Catalina
234
  CATALINA_TMPDIR="$CATALINA_BASE"/temp
235
fi
236
 
237
# Add tomcat-juli.jar to classpath
238
# tomcat-juli.jar can be over-ridden per instance
239
if [ -r "$CATALINA_BASE/bin/tomcat-juli.jar" ] ; then
240
  CLASSPATH=$CLASSPATH:$CATALINA_BASE/bin/tomcat-juli.jar
241
else
242
  CLASSPATH=$CLASSPATH:$CATALINA_HOME/bin/tomcat-juli.jar
243
fi
244
 
245
# Bugzilla 37848: When no TTY is available, don't output to console
246
have_tty=0
247
if [ -t 0 ]; then
248
    have_tty=1
249
fi
250
 
251
# For Cygwin, switch paths to Windows format before running java
252
if $cygwin; then
253
  JAVA_HOME=`cygpath --absolute --windows "$JAVA_HOME"`
254
  JRE_HOME=`cygpath --absolute --windows "$JRE_HOME"`
255
  CATALINA_HOME=`cygpath --absolute --windows "$CATALINA_HOME"`
256
  CATALINA_BASE=`cygpath --absolute --windows "$CATALINA_BASE"`
257
  CATALINA_TMPDIR=`cygpath --absolute --windows "$CATALINA_TMPDIR"`
258
  CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
259
  [ -n "$JAVA_ENDORSED_DIRS" ] && JAVA_ENDORSED_DIRS=`cygpath --path --windows "$JAVA_ENDORSED_DIRS"`
260
fi
261
 
262
if [ -z "$JSSE_OPTS" ] ; then
263
  JSSE_OPTS="-Djdk.tls.ephemeralDHKeySize=2048"
264
fi
265
JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS"
266
 
267
# Register custom URL handlers
268
# Do this here so custom URL handles (specifically 'war:...') can be used in the security policy
269
JAVA_OPTS="$JAVA_OPTS -Djava.protocol.handler.pkgs=org.apache.catalina.webresources"
270
 
271
# Disable the global canonical file name cache to protect against CVE-2024-56337
272
# Note: The cache is disabled by default in Java 12 to 20 inclusive
273
#       The cache is removed in Java 21 onwards
274
# Need to set this here as java.io.FileSystem caches this in a static field during class
275
# initialisation so it needs to be set before any file system access
276
JAVA_OPTS="$JAVA_OPTS -Dsun.io.useCanonCaches=false"
277
 
278
# Check for the deprecated LOGGING_CONFIG
279
# Only use it if CATALINA_LOGGING_CONFIG is not set and LOGGING_CONFIG starts with "-D..."
280
if [ -z "$CATALINA_LOGGING_CONFIG" ]; then
281
  case $LOGGING_CONFIG in
282
    -D*) CATALINA_LOGGING_CONFIG="$LOGGING_CONFIG"
283
  esac
284
fi
285
 
286
# Set juli LogManager config file if it is present and an override has not been issued
287
if [ -z "$CATALINA_LOGGING_CONFIG" ]; then
288
  if [ -r "$CATALINA_BASE"/conf/logging.properties ]; then
289
    CATALINA_LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
290
  else
291
    # Bugzilla 45585
292
    CATALINA_LOGGING_CONFIG="-Dnop"
293
  fi
294
fi
295
 
296
if [ -z "$LOGGING_MANAGER" ]; then
297
  LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
298
fi
299
 
300
# Set UMASK unless it has been overridden
301
if [ -z "$UMASK" ]; then
302
    UMASK="0027"
303
fi
304
umask $UMASK
305
 
306
# Java 9 no longer supports the java.endorsed.dirs
307
# system property. Only try to use it if
308
# JAVA_ENDORSED_DIRS was explicitly set
309
# or CATALINA_HOME/endorsed exists.
310
ENDORSED_PROP=ignore.endorsed.dirs
311
if [ -n "$JAVA_ENDORSED_DIRS" ]; then
312
    ENDORSED_PROP=java.endorsed.dirs
313
fi
314
if [ -d "$CATALINA_HOME/endorsed" ]; then
315
    ENDORSED_PROP=java.endorsed.dirs
316
fi
317
 
318
# Make the umask available when using the org.apache.catalina.security.SecurityListener
319
JAVA_OPTS="$JAVA_OPTS -Dorg.apache.catalina.security.SecurityListener.UMASK=`umask`"
320
 
321
if [ -z "$USE_NOHUP" ]; then
322
    if $hpux; then
323
        USE_NOHUP="true"
324
    else
325
        USE_NOHUP="false"
326
    fi
327
fi
328
unset _NOHUP
329
if [ "$USE_NOHUP" = "true" ]; then
330
    _NOHUP="nohup"
331
fi
332
 
333
# Add the JAVA 9 specific start-up parameters required by Tomcat
334
JDK_JAVA_OPTIONS="$JDK_JAVA_OPTIONS --add-opens=java.base/java.lang=ALL-UNNAMED"
335
JDK_JAVA_OPTIONS="$JDK_JAVA_OPTIONS --add-opens=java.base/java.lang.invoke=ALL-UNNAMED"
336
JDK_JAVA_OPTIONS="$JDK_JAVA_OPTIONS --add-opens=java.base/java.lang.reflect=ALL-UNNAMED"
337
JDK_JAVA_OPTIONS="$JDK_JAVA_OPTIONS --add-opens=java.base/java.io=ALL-UNNAMED"
338
JDK_JAVA_OPTIONS="$JDK_JAVA_OPTIONS --add-opens=java.base/java.util=ALL-UNNAMED"
339
JDK_JAVA_OPTIONS="$JDK_JAVA_OPTIONS --add-opens=java.base/java.util.concurrent=ALL-UNNAMED"
340
JDK_JAVA_OPTIONS="$JDK_JAVA_OPTIONS --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED"
341
export JDK_JAVA_OPTIONS
342
 
343
# ----- Execute The Requested Command -----------------------------------------
344
 
345
# Bugzilla 37848: only output this if we have a TTY
346
if [ $have_tty -eq 1 ]; then
347
  echo "Using CATALINA_BASE:   $CATALINA_BASE"
348
  echo "Using CATALINA_HOME:   $CATALINA_HOME"
349
  echo "Using CATALINA_TMPDIR: $CATALINA_TMPDIR"
350
  if [ "$1" = "debug" ] ; then
351
    echo "Using JAVA_HOME:       $JAVA_HOME"
352
  else
353
    echo "Using JRE_HOME:        $JRE_HOME"
354
  fi
355
  echo "Using CLASSPATH:       $CLASSPATH"
356
  echo "Using CATALINA_OPTS:   $CATALINA_OPTS"
357
  if [ ! -z "$CATALINA_PID" ]; then
358
    echo "Using CATALINA_PID:    $CATALINA_PID"
359
  fi
360
fi
361
 
362
if [ "$1" = "jpda" ] ; then
363
  if [ -z "$JPDA_TRANSPORT" ]; then
364
    JPDA_TRANSPORT="dt_socket"
365
  fi
366
  if [ -z "$JPDA_ADDRESS" ]; then
367
    JPDA_ADDRESS="localhost:8000"
368
  fi
369
  if [ -z "$JPDA_SUSPEND" ]; then
370
    JPDA_SUSPEND="n"
371
  fi
372
  if [ -z "$JPDA_OPTS" ]; then
373
    JPDA_OPTS="-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND"
374
  fi
375
  CATALINA_OPTS="$JPDA_OPTS $CATALINA_OPTS"
376
  shift
377
fi
378
 
379
if [ "$1" = "debug" ] ; then
380
  if $os400; then
381
    echo "Debug command not available on OS400"
382
    exit 1
383
  else
384
    shift
385
    if [ "$1" = "-security" ] ; then
386
      if [ $have_tty -eq 1 ]; then
387
        echo "Using Security Manager"
388
      fi
389
      shift
390
      eval exec "\"$_RUNJDB\"" "\"$CATALINA_LOGGING_CONFIG\"" $LOGGING_MANAGER "$JAVA_OPTS" "$CATALINA_OPTS" \
391
        -D$ENDORSED_PROP="$JAVA_ENDORSED_DIRS" \
392
        -classpath "$CLASSPATH" \
393
        -sourcepath "$CATALINA_HOME"/../../java \
394
        -Djava.security.manager \
395
        -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
396
        -Dcatalina.base="$CATALINA_BASE" \
397
        -Dcatalina.home="$CATALINA_HOME" \
398
        -Djava.io.tmpdir="$CATALINA_TMPDIR" \
399
        org.apache.catalina.startup.Bootstrap "$@" start
400
    else
401
      eval exec "\"$_RUNJDB\"" "\"$CATALINA_LOGGING_CONFIG\"" $LOGGING_MANAGER "$JAVA_OPTS" "$CATALINA_OPTS" \
402
        -D$ENDORSED_PROP="$JAVA_ENDORSED_DIRS" \
403
        -classpath "$CLASSPATH" \
404
        -sourcepath "$CATALINA_HOME"/../../java \
405
        -Dcatalina.base="$CATALINA_BASE" \
406
        -Dcatalina.home="$CATALINA_HOME" \
407
        -Djava.io.tmpdir="$CATALINA_TMPDIR" \
408
        org.apache.catalina.startup.Bootstrap "$@" start
409
    fi
410
  fi
411
 
412
elif [ "$1" = "run" ]; then
413
 
414
  shift
415
  if [ "$1" = "-security" ] ; then
416
    if [ $have_tty -eq 1 ]; then
417
      echo "Using Security Manager"
418
    fi
419
    shift
420
    eval exec "\"$_RUNJAVA\"" "\"$CATALINA_LOGGING_CONFIG\"" $LOGGING_MANAGER "$JAVA_OPTS" "$CATALINA_OPTS" \
421
      -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
422
      -classpath "\"$CLASSPATH\"" \
423
      -Djava.security.manager \
424
      -Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \
425
      -Dcatalina.base="\"$CATALINA_BASE\"" \
426
      -Dcatalina.home="\"$CATALINA_HOME\"" \
427
      -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
428
      org.apache.catalina.startup.Bootstrap "$@" start
429
  else
430
    eval exec "\"$_RUNJAVA\"" "\"$CATALINA_LOGGING_CONFIG\"" $LOGGING_MANAGER "$JAVA_OPTS" "$CATALINA_OPTS" \
431
      -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
432
      -classpath "\"$CLASSPATH\"" \
433
      -Dcatalina.base="\"$CATALINA_BASE\"" \
434
      -Dcatalina.home="\"$CATALINA_HOME\"" \
435
      -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
436
      org.apache.catalina.startup.Bootstrap "$@" start
437
  fi
438
 
439
elif [ "$1" = "start" ] ; then
440
 
441
  if [ ! -z "$CATALINA_PID" ]; then
442
    if [ -f "$CATALINA_PID" ]; then
443
      if [ -s "$CATALINA_PID" ]; then
444
        echo "Existing PID file found during start."
445
        if [ -r "$CATALINA_PID" ]; then
446
          PID=`cat "$CATALINA_PID"`
447
          ps -p $PID >/dev/null 2>&1
448
          if [ $? -eq 0 ] ; then
449
            echo "Tomcat appears to still be running with PID $PID. Start aborted."
450
            echo "If the following process is not a Tomcat process, remove the PID file and try again:"
451
            ps -f -p $PID
452
            exit 1
453
          else
454
            echo "Removing/clearing stale PID file."
455
            rm -f "$CATALINA_PID" >/dev/null 2>&1
456
            if [ $? != 0 ]; then
457
              if [ -w "$CATALINA_PID" ]; then
458
                cat /dev/null > "$CATALINA_PID"
459
              else
460
                echo "Unable to remove or clear stale PID file. Start aborted."
461
                exit 1
462
              fi
463
            fi
464
          fi
465
        else
466
          echo "Unable to read PID file. Start aborted."
467
          exit 1
468
        fi
469
      else
470
        rm -f "$CATALINA_PID" >/dev/null 2>&1
471
        if [ $? != 0 ]; then
472
          if [ ! -w "$CATALINA_PID" ]; then
473
            echo "Unable to remove or write to empty PID file. Start aborted."
474
            exit 1
475
          fi
476
        fi
477
      fi
478
    fi
479
  fi
480
 
481
  shift
482
  if [ -z "$CATALINA_OUT_CMD" ] ; then
483
    touch "$CATALINA_OUT"
484
  else
485
    if [ ! -e "$CATALINA_OUT" ]; then
486
      if ! mkfifo "$CATALINA_OUT"; then
487
        echo "cannot create named pipe $CATALINA_OUT. Start aborted."
488
        exit 1
489
      fi
490
    elif [ ! -p "$CATALINA_OUT" ]; then
491
      echo "$CATALINA_OUT exists and is not a named pipe. Start aborted."
492
      exit 1
493
    fi
494
    $CATALINA_OUT_CMD <"$CATALINA_OUT" &
495
  fi
496
  if [ "$1" = "-security" ] ; then
497
    if [ $have_tty -eq 1 ]; then
498
      echo "Using Security Manager"
499
    fi
500
    shift
501
    eval $_NOHUP "\"$_RUNJAVA\"" "\"$CATALINA_LOGGING_CONFIG\"" $LOGGING_MANAGER "$JAVA_OPTS" "$CATALINA_OPTS" \
502
      -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
503
      -classpath "\"$CLASSPATH\"" \
504
      -Djava.security.manager \
505
      -Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \
506
      -Dcatalina.base="\"$CATALINA_BASE\"" \
507
      -Dcatalina.home="\"$CATALINA_HOME\"" \
508
      -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
509
      org.apache.catalina.startup.Bootstrap "$@" start \
510
      >> "$CATALINA_OUT" 2>&1 "&"
511
 
512
  else
513
    eval $_NOHUP "\"$_RUNJAVA\"" "\"$CATALINA_LOGGING_CONFIG\"" $LOGGING_MANAGER "$JAVA_OPTS" "$CATALINA_OPTS" \
514
      -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
515
      -classpath "\"$CLASSPATH\"" \
516
      -Dcatalina.base="\"$CATALINA_BASE\"" \
517
      -Dcatalina.home="\"$CATALINA_HOME\"" \
518
      -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
519
      org.apache.catalina.startup.Bootstrap "$@" start \
520
      >> "$CATALINA_OUT" 2>&1 "&"
521
 
522
  fi
523
 
524
  if [ ! -z "$CATALINA_PID" ]; then
525
    echo $! > "$CATALINA_PID"
526
  fi
527
 
528
  echo "Tomcat started."
529
 
530
elif [ "$1" = "stop" ] ; then
531
 
532
  shift
533
 
534
  SLEEP=5
535
  if [ ! -z "$1" ]; then
536
    echo $1 | grep "[^0-9]" >/dev/null 2>&1
537
    if [ $? -gt 0 ]; then
538
      SLEEP=$1
539
      shift
540
    fi
541
  fi
542
 
543
  FORCE=0
544
  if [ "$1" = "-force" ]; then
545
    shift
546
    FORCE=1
547
  fi
548
 
549
  if [ ! -z "$CATALINA_PID" ]; then
550
    if [ -f "$CATALINA_PID" ]; then
551
      if [ -s "$CATALINA_PID" ]; then
552
        kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1
553
        if [ $? -gt 0 ]; then
554
          echo "PID file found but either no matching process was found or the current user does not have permission to stop the process. Stop aborted."
555
          exit 1
556
        fi
557
      else
558
        echo "PID file is empty and has been ignored."
559
      fi
560
    else
561
      echo "\$CATALINA_PID was set but the specified file does not exist. Is Tomcat running? Stop aborted."
562
      exit 1
563
    fi
564
  fi
565
 
566
  eval "\"$_RUNJAVA\"" $LOGGING_MANAGER "$JAVA_OPTS" \
567
    -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
568
    -classpath "\"$CLASSPATH\"" \
569
    -Dcatalina.base="\"$CATALINA_BASE\"" \
570
    -Dcatalina.home="\"$CATALINA_HOME\"" \
571
    -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
572
    org.apache.catalina.startup.Bootstrap "$@" stop
573
 
574
  # stop failed. Shutdown port disabled? Try a normal kill.
575
  if [ $? != 0 ]; then
576
    if [ ! -z "$CATALINA_PID" ]; then
577
      echo "The stop command failed. Attempting to signal the process to stop through OS signal."
578
      kill -15 `cat "$CATALINA_PID"` >/dev/null 2>&1
579
    fi
580
  fi
581
 
582
  if [ ! -z "$CATALINA_PID" ]; then
583
    if [ -f "$CATALINA_PID" ]; then
584
      while [ $SLEEP -ge 0 ]; do
585
        kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1
586
        if [ $? -gt 0 ]; then
587
          rm -f "$CATALINA_PID" >/dev/null 2>&1
588
          if [ $? != 0 ]; then
589
            if [ -w "$CATALINA_PID" ]; then
590
              cat /dev/null > "$CATALINA_PID"
591
              # If Tomcat has stopped don't try and force a stop with an empty PID file
592
              FORCE=0
593
            else
594
              echo "The PID file could not be removed or cleared."
595
            fi
596
          fi
597
          echo "Tomcat stopped."
598
          break
599
        fi
600
        if [ $SLEEP -gt 0 ]; then
601
          sleep 1
602
        fi
603
        if [ $SLEEP -eq 0 ]; then
604
          echo "Tomcat did not stop in time."
605
          if [ $FORCE -eq 0 ]; then
606
            echo "PID file was not removed."
607
          fi
608
          echo "To aid diagnostics a thread dump has been written to standard out."
609
          kill -3 `cat "$CATALINA_PID"`
610
        fi
611
        SLEEP=`expr $SLEEP - 1 `
612
      done
613
    fi
614
  fi
615
 
616
  KILL_SLEEP_INTERVAL=5
617
  if [ $FORCE -eq 1 ]; then
618
    if [ -z "$CATALINA_PID" ]; then
619
      echo "Kill failed: \$CATALINA_PID not set"
620
    else
621
      if [ -f "$CATALINA_PID" ]; then
622
        PID=`cat "$CATALINA_PID"`
623
        echo "Killing Tomcat with the PID: $PID"
624
        kill -9 $PID
625
        while [ $KILL_SLEEP_INTERVAL -ge 0 ]; do
626
            kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1
627
            if [ $? -gt 0 ]; then
628
                rm -f "$CATALINA_PID" >/dev/null 2>&1
629
                if [ $? != 0 ]; then
630
                    if [ -w "$CATALINA_PID" ]; then
631
                        cat /dev/null > "$CATALINA_PID"
632
                    else
633
                        echo "The PID file could not be removed."
634
                    fi
635
                fi
636
                echo "The Tomcat process has been killed."
637
                break
638
            fi
639
            if [ $KILL_SLEEP_INTERVAL -gt 0 ]; then
640
                sleep 1
641
            fi
642
            KILL_SLEEP_INTERVAL=`expr $KILL_SLEEP_INTERVAL - 1 `
643
        done
644
        if [ $KILL_SLEEP_INTERVAL -lt 0 ]; then
645
            echo "Tomcat has not been killed completely yet. The process might be waiting on some system call or might be UNINTERRUPTIBLE."
646
        fi
647
      fi
648
    fi
649
  fi
650
 
651
elif [ "$1" = "configtest" ] ; then
652
 
653
    eval "\"$_RUNJAVA\"" $LOGGING_MANAGER "$JAVA_OPTS" \
654
      -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
655
      -classpath "\"$CLASSPATH\"" \
656
      -Dcatalina.base="\"$CATALINA_BASE\"" \
657
      -Dcatalina.home="\"$CATALINA_HOME\"" \
658
      -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
659
      org.apache.catalina.startup.Bootstrap configtest
660
    result=$?
661
    if [ $result -ne 0 ]; then
662
        echo "Configuration error detected!"
663
    fi
664
    exit $result
665
 
666
elif [ "$1" = "version" ] ; then
667
 
668
   eval "\"$_RUNJAVA\"" "$JAVA_OPTS" \
669
         -classpath "\"$CATALINA_HOME/lib/catalina.jar\"" \
670
         org.apache.catalina.util.ServerInfo
671
 
672
else
673
 
674
  echo "Usage: catalina.sh ( commands ... )"
675
  echo "commands:"
676
  if $os400; then
677
    echo "  debug             Start Catalina in a debugger (not available on OS400)"
678
    echo "  debug -security   Debug Catalina with a security manager (not available on OS400)"
679
  else
680
    echo "  debug             Start Catalina in a debugger"
681
    echo "  debug -security   Debug Catalina with a security manager"
682
  fi
683
  echo "  jpda start        Start Catalina under JPDA debugger"
684
  echo "  run               Start Catalina in the current window"
685
  echo "  run -security     Start in the current window with security manager"
686
  echo "  start             Start Catalina in a separate window"
687
  echo "  start -security   Start in a separate window with security manager"
688
  echo "  stop              Stop Catalina, waiting up to 5 seconds for the process to end"
689
  echo "  stop n            Stop Catalina, waiting up to n seconds for the process to end"
690
  echo "  stop -force       Stop Catalina, wait up to 5 seconds and then use kill -KILL if still running"
691
  echo "  stop n -force     Stop Catalina, wait up to n seconds and then use kill -KILL if still running"
692
  echo "  configtest        Run a basic syntax check on server.xml - check exit code for result"
693
  echo "  version           What version of tomcat are you running?"
694
  echo "Note: Waiting for the process to end and use of the -force option require that \$CATALINA_PID is defined"
695
  exit 1
696
 
697
fi