~ubuntu-branches/ubuntu/maverick/tomcat6/maverick

« back to all changes in this revision

Viewing changes to .pc/allow-empty-pid-file.patch/bin/catalina.sh

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2010-06-28 21:41:31 UTC
  • mfrom: (2.2.15 sid)
  • Revision ID: james.westby@ubuntu.com-20100628214131-3wktukpb3lgdf83h
Tags: 6.0.26-5
* Convert patches to dep3 format.
* Backport security fix from trunk to fix CVE-2010-1157. (Closes: #587447)
* Set urgency to medium due to the security fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
# Start/Stop Script for the CATALINA Server
20
 
#
21
 
# Environment Variable Prequisites
22
 
#
23
 
#   CATALINA_HOME   May point at your Catalina "build" directory.
24
 
#
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.
28
 
#
29
 
#   CATALINA_OUT    (Optional) Full path to a file where stdout and stderr
30
 
#                   will be redirected. 
31
 
#                   Default is $CATALINA_BASE/logs/catalina.out
32
 
#
33
 
#   CATALINA_OPTS   (Optional) Java runtime options used when the "start",
34
 
#                   or "run" command is executed.
35
 
#
36
 
#   CATALINA_TMPDIR (Optional) Directory path location of temporary directory
37
 
#                   the JVM should use (java.io.tmpdir).  Defaults to
38
 
#                   $CATALINA_BASE/temp.
39
 
#
40
 
#   JAVA_HOME       Must point at your Java Development Kit installation.
41
 
#                   Required to run the with the "debug" argument.
42
 
#
43
 
#   JRE_HOME        Must point at your Java Development Kit installation.
44
 
#                   Defaults to JAVA_HOME if empty.
45
 
#
46
 
#   JAVA_OPTS       (Optional) Java runtime options used when the "start",
47
 
#                   "stop", or "run" command is executed.
48
 
#
49
 
#   JPDA_TRANSPORT  (Optional) JPDA transport used when the "jpda start"
50
 
#                   command is executed. The default is "dt_socket".
51
 
#
52
 
#   JPDA_ADDRESS    (Optional) Java runtime options used when the "jpda start"
53
 
#                   command is executed. The default is 8000.
54
 
#
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".
58
 
#
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:
63
 
#
64
 
#                   -agentlib:jdwp=transport=$JPDA_TRANSPORT,
65
 
#                       address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND
66
 
#
67
 
#   CATALINA_PID    (Optional) Path of the file which should contains the pid
68
 
#                   of catalina startup java process, when start (fork) is used
69
 
#
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"
73
 
#
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"
77
 
#
78
 
# $Id: catalina.sh 885002 2009-11-27 20:51:03Z markt $
79
 
# -----------------------------------------------------------------------------
80
 
 
81
 
# OS specific support.  $var _must_ be set to either true or false.
82
 
cygwin=false
83
 
os400=false
84
 
darwin=false
85
 
case "`uname`" in
86
 
CYGWIN*) cygwin=true;;
87
 
OS400*) os400=true;;
88
 
Darwin*) darwin=true;;
89
 
esac
90
 
 
91
 
# resolve links - $0 may be a softlink
92
 
PRG="$0"
93
 
 
94
 
while [ -h "$PRG" ]; do
95
 
  ls=`ls -ld "$PRG"`
96
 
  link=`expr "$ls" : '.*-> \(.*\)$'`
97
 
  if expr "$link" : '/.*' > /dev/null; then
98
 
    PRG="$link"
99
 
  else
100
 
    PRG=`dirname "$PRG"`/"$link"
101
 
  fi
102
 
done
103
 
 
104
 
# Get standard environment variables
105
 
PRGDIR=`dirname "$PRG"`
106
 
 
107
 
# Only set CATALINA_HOME if not already set
108
 
[ -z "$CATALINA_HOME" ] && CATALINA_HOME=`cd "$PRGDIR/.." ; pwd`
109
 
 
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.
112
 
CLASSPATH=
113
 
 
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
118
 
fi
119
 
 
120
 
# For Cygwin, ensure paths are in UNIX format before anything is touched
121
 
if $cygwin; then
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"`
127
 
fi
128
 
 
129
 
# For OS400
130
 
if $os400; then
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)'
135
 
  system $COMMAND
136
 
 
137
 
  # Enable multi threading
138
 
  export QIBM_MULTI_THREADED=Y
139
 
fi
140
 
 
141
 
# Get standard Java environment variables
142
 
if $os400; then
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 
149
 
else
150
 
  if [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then
151
 
    BASEDIR="$CATALINA_HOME"
152
 
    . "$CATALINA_HOME"/bin/setclasspath.sh
153
 
  else
154
 
    echo "Cannot find $CATALINA_HOME/bin/setclasspath.sh"
155
 
    echo "This file is needed to run this program"
156
 
    exit 1
157
 
  fi
158
 
fi
159
 
 
160
 
if [ -z "$CATALINA_BASE" ] ; then
161
 
  CATALINA_BASE="$CATALINA_HOME"
162
 
fi
163
 
 
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":
168
 
fi
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
171
 
else
172
 
  CLASSPATH="$CLASSPATH""$CATALINA_HOME"/bin/bootstrap.jar
173
 
fi
174
 
 
175
 
if [ -z "$CATALINA_OUT" ] ; then
176
 
  CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
177
 
fi
178
 
 
179
 
if [ -z "$CATALINA_TMPDIR" ] ; then
180
 
  # Define the java.io.tmpdir to use for Catalina
181
 
  CATALINA_TMPDIR="$CATALINA_BASE"/temp
182
 
fi
183
 
 
184
 
# Bugzilla 37848: When no TTY is available, don't output to console
185
 
have_tty=0
186
 
if [ "`tty`" != "not a tty" ]; then
187
 
    have_tty=1
188
 
fi
189
 
 
190
 
# For Cygwin, switch paths to Windows format before running java
191
 
if $cygwin; then
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"`
199
 
fi
200
 
 
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"
205
 
  else
206
 
    # Bugzilla 45585
207
 
    LOGGING_CONFIG="-Dnop"
208
 
  fi
209
 
fi
210
 
 
211
 
if [ -z "$LOGGING_MANAGER" ]; then
212
 
  JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
213
 
else 
214
 
  JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER"
215
 
fi
216
 
 
217
 
# ----- Execute The Requested Command -----------------------------------------
218
 
 
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"
226
 
  else
227
 
    echo "Using JRE_HOME:        $JRE_HOME"
228
 
  fi
229
 
  echo "Using CLASSPATH:       $CLASSPATH"
230
 
fi
231
 
 
232
 
if [ "$1" = "jpda" ] ; then
233
 
  if [ -z "$JPDA_TRANSPORT" ]; then
234
 
    JPDA_TRANSPORT="dt_socket"
235
 
  fi
236
 
  if [ -z "$JPDA_ADDRESS" ]; then
237
 
    JPDA_ADDRESS="8000"
238
 
  fi
239
 
  if [ -z "$JPDA_SUSPEND" ]; then
240
 
    JPDA_SUSPEND="n"
241
 
  fi
242
 
  if [ -z "$JPDA_OPTS" ]; then
243
 
    JPDA_OPTS="-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND"
244
 
  fi
245
 
  CATALINA_OPTS="$CATALINA_OPTS $JPDA_OPTS"
246
 
  shift
247
 
fi
248
 
 
249
 
if [ "$1" = "debug" ] ; then
250
 
  if $os400; then
251
 
    echo "Debug command not available on OS400"
252
 
    exit 1
253
 
  else
254
 
    shift
255
 
    if [ "$1" = "-security" ] ; then
256
 
      if [ $have_tty -eq 1 ]; then
257
 
        echo "Using Security Manager"
258
 
      fi
259
 
      shift
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
269
 
    else
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
277
 
    fi
278
 
  fi
279
 
 
280
 
elif [ "$1" = "run" ]; then
281
 
 
282
 
  shift
283
 
  if [ "$1" = "-security" ] ; then
284
 
    if [ $have_tty -eq 1 ]; then
285
 
      echo "Using Security Manager"
286
 
    fi
287
 
    shift
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
296
 
  else
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
303
 
  fi
304
 
 
305
 
elif [ "$1" = "start" ] ; then
306
 
 
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."
310
 
      exit 1
311
 
    fi
312
 
  fi
313
 
 
314
 
  shift
315
 
  touch "$CATALINA_OUT"
316
 
  if [ "$1" = "-security" ] ; then
317
 
    if [ $have_tty -eq 1 ]; then
318
 
      echo "Using Security Manager"
319
 
    fi
320
 
    shift
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 &
330
 
 
331
 
  else
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 &
339
 
 
340
 
  fi
341
 
 
342
 
  if [ ! -z "$CATALINA_PID" ]; then
343
 
    echo $! > $CATALINA_PID
344
 
  fi
345
 
 
346
 
elif [ "$1" = "stop" ] ; then
347
 
 
348
 
  shift
349
 
 
350
 
  SLEEP=5
351
 
  if [ ! -z "$1" ]; then
352
 
    echo $1 | grep "[^0-9]" > /dev/null 2>&1
353
 
    if [ $? -eq 1 ]; then
354
 
      SLEEP=$1
355
 
      shift
356
 
    fi
357
 
  fi
358
 
 
359
 
  FORCE=0
360
 
  if [ "$1" = "-force" ]; then
361
 
    shift
362
 
    FORCE=1
363
 
  fi
364
 
 
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."
370
 
        exit 1
371
 
      fi
372
 
    else
373
 
      echo "\$CATALINA_PID was set ($CATALINA_PID) but the specified file does not exist. Is Tomcat running? Stop aborted."
374
 
      exit 1
375
 
    fi
376
 
  fi
377
 
  
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
384
 
 
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
390
 
          rm $CATALINA_PID
391
 
          break
392
 
        fi
393
 
        if [ $SLEEP -gt 0 ]; then
394
 
          sleep 1
395
 
        fi
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."
399
 
          fi
400
 
        fi
401
 
        SLEEP=`expr $SLEEP - 1 `
402
 
      done
403
 
    fi
404
 
  fi
405
 
 
406
 
  if [ $FORCE -eq 1 ]; then
407
 
    if [ -z "$CATALINA_PID" ]; then
408
 
      echo "Kill failed: \$CATALINA_PID not set"
409
 
    else
410
 
      if [ -f "$CATALINA_PID" ]; then
411
 
        echo "Killing: `cat $CATALINA_PID`"
412
 
        kill -9 `cat $CATALINA_PID`
413
 
        rm $CATALINA_PID
414
 
      fi
415
 
    fi
416
 
  fi
417
 
 
418
 
elif [ "$1" = "version" ] ; then
419
 
 
420
 
    "$_RUNJAVA"   \
421
 
      -classpath "$CATALINA_HOME/lib/catalina.jar" \
422
 
      org.apache.catalina.util.ServerInfo
423
 
 
424
 
else
425
 
 
426
 
  echo "Usage: catalina.sh ( commands ... )"
427
 
  echo "commands:"
428
 
  if $os400; then
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)"
431
 
  else
432
 
    echo "  debug             Start Catalina in a debugger"
433
 
    echo "  debug -security   Debug Catalina with a security manager"
434
 
  fi
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"
446
 
  exit 1
447
 
 
448
 
fi