"Fossies" - the Fresh Open Source Software Archive

Member "apache-tomcat-8.5.58/bin/catalina.sh" (10 Sep 2020, 25292 Bytes) of package /windows/www/apache-tomcat-8.5.58-windows-x86.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "catalina.sh": 8.5.57_vs_8.5.58.

    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 # Check for the deprecated LOGGING_CONFIG
  272 # Only use it if CATALINA_LOGGING_CONFIG is not set and LOGGING_CONFIG starts with "-D..."
  273 if [ -z "$CATALINA_LOGGING_CONFIG" ]; then
  274   case $LOGGING_CONFIG in
  275     -D*) CATALINA_LOGGING_CONFIG="$LOGGING_CONFIG"
  276   esac
  277 fi
  278 
  279 # Set juli LogManager config file if it is present and an override has not been issued
  280 if [ -z "$CATALINA_LOGGING_CONFIG" ]; then
  281   if [ -r "$CATALINA_BASE"/conf/logging.properties ]; then
  282     CATALINA_LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
  283   else
  284     # Bugzilla 45585
  285     CATALINA_LOGGING_CONFIG="-Dnop"
  286   fi
  287 fi
  288 
  289 if [ -z "$LOGGING_MANAGER" ]; then
  290   LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
  291 fi
  292 
  293 # Set UMASK unless it has been overridden
  294 if [ -z "$UMASK" ]; then
  295     UMASK="0027"
  296 fi
  297 umask $UMASK
  298 
  299 # Java 9 no longer supports the java.endorsed.dirs
  300 # system property. Only try to use it if
  301 # JAVA_ENDORSED_DIRS was explicitly set
  302 # or CATALINA_HOME/endorsed exists.
  303 ENDORSED_PROP=ignore.endorsed.dirs
  304 if [ -n "$JAVA_ENDORSED_DIRS" ]; then
  305     ENDORSED_PROP=java.endorsed.dirs
  306 fi
  307 if [ -d "$CATALINA_HOME/endorsed" ]; then
  308     ENDORSED_PROP=java.endorsed.dirs
  309 fi
  310 
  311 # Make the umask available when using the org.apache.catalina.security.SecurityListener
  312 JAVA_OPTS="$JAVA_OPTS -Dorg.apache.catalina.security.SecurityListener.UMASK=`umask`"
  313 
  314 if [ -z "$USE_NOHUP" ]; then
  315     if $hpux; then
  316         USE_NOHUP="true"
  317     else
  318         USE_NOHUP="false"
  319     fi
  320 fi
  321 unset _NOHUP
  322 if [ "$USE_NOHUP" = "true" ]; then
  323     _NOHUP="nohup"
  324 fi
  325 
  326 # Add the JAVA 9 specific start-up parameters required by Tomcat
  327 JDK_JAVA_OPTIONS="$JDK_JAVA_OPTIONS --add-opens=java.base/java.lang=ALL-UNNAMED"
  328 JDK_JAVA_OPTIONS="$JDK_JAVA_OPTIONS --add-opens=java.base/java.io=ALL-UNNAMED"
  329 JDK_JAVA_OPTIONS="$JDK_JAVA_OPTIONS --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED"
  330 export JDK_JAVA_OPTIONS
  331 
  332 # ----- Execute The Requested Command -----------------------------------------
  333 
  334 # Bugzilla 37848: only output this if we have a TTY
  335 if [ $have_tty -eq 1 ]; then
  336   echo "Using CATALINA_BASE:   $CATALINA_BASE"
  337   echo "Using CATALINA_HOME:   $CATALINA_HOME"
  338   echo "Using CATALINA_TMPDIR: $CATALINA_TMPDIR"
  339   if [ "$1" = "debug" ] ; then
  340     echo "Using JAVA_HOME:       $JAVA_HOME"
  341   else
  342     echo "Using JRE_HOME:        $JRE_HOME"
  343   fi
  344   echo "Using CLASSPATH:       $CLASSPATH"
  345   echo "Using CATALINA_OPTS:   $CATALINA_OPTS"
  346   if [ ! -z "$CATALINA_PID" ]; then
  347     echo "Using CATALINA_PID:    $CATALINA_PID"
  348   fi
  349 fi
  350 
  351 if [ "$1" = "jpda" ] ; then
  352   if [ -z "$JPDA_TRANSPORT" ]; then
  353     JPDA_TRANSPORT="dt_socket"
  354   fi
  355   if [ -z "$JPDA_ADDRESS" ]; then
  356     JPDA_ADDRESS="localhost:8000"
  357   fi
  358   if [ -z "$JPDA_SUSPEND" ]; then
  359     JPDA_SUSPEND="n"
  360   fi
  361   if [ -z "$JPDA_OPTS" ]; then
  362     JPDA_OPTS="-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND"
  363   fi
  364   CATALINA_OPTS="$JPDA_OPTS $CATALINA_OPTS"
  365   shift
  366 fi
  367 
  368 # TODO: Bugzilla 63815
  369 # This doesn't currently work (and can't be made to work) if values used in
  370 # CATALINA_OPTS and/or JAVA_OPTS require quoting. See:
  371 # https://bugs.openjdk.java.net/browse/JDK-8234808
  372 if [ "$1" = "debug" ] ; then
  373   if $os400; then
  374     echo "Debug command not available on OS400"
  375     exit 1
  376   else
  377     shift
  378     if [ "$1" = "-security" ] ; then
  379       if [ $have_tty -eq 1 ]; then
  380         echo "Using Security Manager"
  381       fi
  382       shift
  383       exec "$_RUNJDB" "$CATALINA_LOGGING_CONFIG" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
  384         -D$ENDORSED_PROP="$JAVA_ENDORSED_DIRS" \
  385         -classpath "$CLASSPATH" \
  386         -sourcepath "$CATALINA_HOME"/../../java \
  387         -Djava.security.manager \
  388         -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
  389         -Dcatalina.base="$CATALINA_BASE" \
  390         -Dcatalina.home="$CATALINA_HOME" \
  391         -Djava.io.tmpdir="$CATALINA_TMPDIR" \
  392         org.apache.catalina.startup.Bootstrap "$@" start
  393     else
  394       exec "$_RUNJDB" "$CATALINA_LOGGING_CONFIG" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
  395         -D$ENDORSED_PROP="$JAVA_ENDORSED_DIRS" \
  396         -classpath "$CLASSPATH" \
  397         -sourcepath "$CATALINA_HOME"/../../java \
  398         -Dcatalina.base="$CATALINA_BASE" \
  399         -Dcatalina.home="$CATALINA_HOME" \
  400         -Djava.io.tmpdir="$CATALINA_TMPDIR" \
  401         org.apache.catalina.startup.Bootstrap "$@" start
  402     fi
  403   fi
  404 
  405 elif [ "$1" = "run" ]; then
  406 
  407   shift
  408   if [ "$1" = "-security" ] ; then
  409     if [ $have_tty -eq 1 ]; then
  410       echo "Using Security Manager"
  411     fi
  412     shift
  413     eval exec "\"$_RUNJAVA\"" "\"$CATALINA_LOGGING_CONFIG\"" $LOGGING_MANAGER "$JAVA_OPTS" "$CATALINA_OPTS" \
  414       -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
  415       -classpath "\"$CLASSPATH\"" \
  416       -Djava.security.manager \
  417       -Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \
  418       -Dcatalina.base="\"$CATALINA_BASE\"" \
  419       -Dcatalina.home="\"$CATALINA_HOME\"" \
  420       -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
  421       org.apache.catalina.startup.Bootstrap "$@" start
  422   else
  423     eval exec "\"$_RUNJAVA\"" "\"$CATALINA_LOGGING_CONFIG\"" $LOGGING_MANAGER "$JAVA_OPTS" "$CATALINA_OPTS" \
  424       -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
  425       -classpath "\"$CLASSPATH\"" \
  426       -Dcatalina.base="\"$CATALINA_BASE\"" \
  427       -Dcatalina.home="\"$CATALINA_HOME\"" \
  428       -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
  429       org.apache.catalina.startup.Bootstrap "$@" start
  430   fi
  431 
  432 elif [ "$1" = "start" ] ; then
  433 
  434   if [ ! -z "$CATALINA_PID" ]; then
  435     if [ -f "$CATALINA_PID" ]; then
  436       if [ -s "$CATALINA_PID" ]; then
  437         echo "Existing PID file found during start."
  438         if [ -r "$CATALINA_PID" ]; then
  439           PID=`cat "$CATALINA_PID"`
  440           ps -p $PID >/dev/null 2>&1
  441           if [ $? -eq 0 ] ; then
  442             echo "Tomcat appears to still be running with PID $PID. Start aborted."
  443             echo "If the following process is not a Tomcat process, remove the PID file and try again:"
  444             ps -f -p $PID
  445             exit 1
  446           else
  447             echo "Removing/clearing stale PID file."
  448             rm -f "$CATALINA_PID" >/dev/null 2>&1
  449             if [ $? != 0 ]; then
  450               if [ -w "$CATALINA_PID" ]; then
  451                 cat /dev/null > "$CATALINA_PID"
  452               else
  453                 echo "Unable to remove or clear stale PID file. Start aborted."
  454                 exit 1
  455               fi
  456             fi
  457           fi
  458         else
  459           echo "Unable to read PID file. Start aborted."
  460           exit 1
  461         fi
  462       else
  463         rm -f "$CATALINA_PID" >/dev/null 2>&1
  464         if [ $? != 0 ]; then
  465           if [ ! -w "$CATALINA_PID" ]; then
  466             echo "Unable to remove or write to empty PID file. Start aborted."
  467             exit 1
  468           fi
  469         fi
  470       fi
  471     fi
  472   fi
  473 
  474   shift
  475   if [ -z "$CATALINA_OUT_CMD" ] ; then
  476     touch "$CATALINA_OUT"
  477   else
  478     if [ ! -e "$CATALINA_OUT" ]; then
  479       if ! mkfifo "$CATALINA_OUT"; then
  480         echo "cannot create named pipe $CATALINA_OUT. Start aborted."
  481         exit 1
  482       fi
  483     elif [ ! -p "$CATALINA_OUT" ]; then
  484       echo "$CATALINA_OUT exists and is not a named pipe. Start aborted."
  485       exit 1
  486     fi
  487     $CATALINA_OUT_CMD <"$CATALINA_OUT" &
  488   fi
  489   if [ "$1" = "-security" ] ; then
  490     if [ $have_tty -eq 1 ]; then
  491       echo "Using Security Manager"
  492     fi
  493     shift
  494     eval $_NOHUP "\"$_RUNJAVA\"" "\"$CATALINA_LOGGING_CONFIG\"" $LOGGING_MANAGER "$JAVA_OPTS" "$CATALINA_OPTS" \
  495       -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
  496       -classpath "\"$CLASSPATH\"" \
  497       -Djava.security.manager \
  498       -Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \
  499       -Dcatalina.base="\"$CATALINA_BASE\"" \
  500       -Dcatalina.home="\"$CATALINA_HOME\"" \
  501       -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
  502       org.apache.catalina.startup.Bootstrap "$@" start \
  503       >> "$CATALINA_OUT" 2>&1 "&"
  504 
  505   else
  506     eval $_NOHUP "\"$_RUNJAVA\"" "\"$CATALINA_LOGGING_CONFIG\"" $LOGGING_MANAGER "$JAVA_OPTS" "$CATALINA_OPTS" \
  507       -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
  508       -classpath "\"$CLASSPATH\"" \
  509       -Dcatalina.base="\"$CATALINA_BASE\"" \
  510       -Dcatalina.home="\"$CATALINA_HOME\"" \
  511       -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
  512       org.apache.catalina.startup.Bootstrap "$@" start \
  513       >> "$CATALINA_OUT" 2>&1 "&"
  514 
  515   fi
  516 
  517   if [ ! -z "$CATALINA_PID" ]; then
  518     echo $! > "$CATALINA_PID"
  519   fi
  520 
  521   echo "Tomcat started."
  522 
  523 elif [ "$1" = "stop" ] ; then
  524 
  525   shift
  526 
  527   SLEEP=5
  528   if [ ! -z "$1" ]; then
  529     echo $1 | grep "[^0-9]" >/dev/null 2>&1
  530     if [ $? -gt 0 ]; then
  531       SLEEP=$1
  532       shift
  533     fi
  534   fi
  535 
  536   FORCE=0
  537   if [ "$1" = "-force" ]; then
  538     shift
  539     FORCE=1
  540   fi
  541 
  542   if [ ! -z "$CATALINA_PID" ]; then
  543     if [ -f "$CATALINA_PID" ]; then
  544       if [ -s "$CATALINA_PID" ]; then
  545         kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1
  546         if [ $? -gt 0 ]; then
  547           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."
  548           exit 1
  549         fi
  550       else
  551         echo "PID file is empty and has been ignored."
  552       fi
  553     else
  554       echo "\$CATALINA_PID was set but the specified file does not exist. Is Tomcat running? Stop aborted."
  555       exit 1
  556     fi
  557   fi
  558 
  559   eval "\"$_RUNJAVA\"" $LOGGING_MANAGER "$JAVA_OPTS" \
  560     -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
  561     -classpath "\"$CLASSPATH\"" \
  562     -Dcatalina.base="\"$CATALINA_BASE\"" \
  563     -Dcatalina.home="\"$CATALINA_HOME\"" \
  564     -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
  565     org.apache.catalina.startup.Bootstrap "$@" stop
  566 
  567   # stop failed. Shutdown port disabled? Try a normal kill.
  568   if [ $? != 0 ]; then
  569     if [ ! -z "$CATALINA_PID" ]; then
  570       echo "The stop command failed. Attempting to signal the process to stop through OS signal."
  571       kill -15 `cat "$CATALINA_PID"` >/dev/null 2>&1
  572     fi
  573   fi
  574 
  575   if [ ! -z "$CATALINA_PID" ]; then
  576     if [ -f "$CATALINA_PID" ]; then
  577       while [ $SLEEP -ge 0 ]; do
  578         kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1
  579         if [ $? -gt 0 ]; then
  580           rm -f "$CATALINA_PID" >/dev/null 2>&1
  581           if [ $? != 0 ]; then
  582             if [ -w "$CATALINA_PID" ]; then
  583               cat /dev/null > "$CATALINA_PID"
  584               # If Tomcat has stopped don't try and force a stop with an empty PID file
  585               FORCE=0
  586             else
  587               echo "The PID file could not be removed or cleared."
  588             fi
  589           fi
  590           echo "Tomcat stopped."
  591           break
  592         fi
  593         if [ $SLEEP -gt 0 ]; then
  594           sleep 1
  595         fi
  596         if [ $SLEEP -eq 0 ]; then
  597           echo "Tomcat did not stop in time."
  598           if [ $FORCE -eq 0 ]; then
  599             echo "PID file was not removed."
  600           fi
  601           echo "To aid diagnostics a thread dump has been written to standard out."
  602           kill -3 `cat "$CATALINA_PID"`
  603         fi
  604         SLEEP=`expr $SLEEP - 1 `
  605       done
  606     fi
  607   fi
  608 
  609   KILL_SLEEP_INTERVAL=5
  610   if [ $FORCE -eq 1 ]; then
  611     if [ -z "$CATALINA_PID" ]; then
  612       echo "Kill failed: \$CATALINA_PID not set"
  613     else
  614       if [ -f "$CATALINA_PID" ]; then
  615         PID=`cat "$CATALINA_PID"`
  616         echo "Killing Tomcat with the PID: $PID"
  617         kill -9 $PID
  618         while [ $KILL_SLEEP_INTERVAL -ge 0 ]; do
  619             kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1
  620             if [ $? -gt 0 ]; then
  621                 rm -f "$CATALINA_PID" >/dev/null 2>&1
  622                 if [ $? != 0 ]; then
  623                     if [ -w "$CATALINA_PID" ]; then
  624                         cat /dev/null > "$CATALINA_PID"
  625                     else
  626                         echo "The PID file could not be removed."
  627                     fi
  628                 fi
  629                 echo "The Tomcat process has been killed."
  630                 break
  631             fi
  632             if [ $KILL_SLEEP_INTERVAL -gt 0 ]; then
  633                 sleep 1
  634             fi
  635             KILL_SLEEP_INTERVAL=`expr $KILL_SLEEP_INTERVAL - 1 `
  636         done
  637         if [ $KILL_SLEEP_INTERVAL -lt 0 ]; then
  638             echo "Tomcat has not been killed completely yet. The process might be waiting on some system call or might be UNINTERRUPTIBLE."
  639         fi
  640       fi
  641     fi
  642   fi
  643 
  644 elif [ "$1" = "configtest" ] ; then
  645 
  646     eval "\"$_RUNJAVA\"" $LOGGING_MANAGER "$JAVA_OPTS" \
  647       -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
  648       -classpath "\"$CLASSPATH\"" \
  649       -Dcatalina.base="\"$CATALINA_BASE\"" \
  650       -Dcatalina.home="\"$CATALINA_HOME\"" \
  651       -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
  652       org.apache.catalina.startup.Bootstrap configtest
  653     result=$?
  654     if [ $result -ne 0 ]; then
  655         echo "Configuration error detected!"
  656     fi
  657     exit $result
  658 
  659 elif [ "$1" = "version" ] ; then
  660 
  661     "$_RUNJAVA"   \
  662       -classpath "$CATALINA_HOME/lib/catalina.jar" \
  663       org.apache.catalina.util.ServerInfo
  664 
  665 else
  666 
  667   echo "Usage: catalina.sh ( commands ... )"
  668   echo "commands:"
  669   if $os400; then
  670     echo "  debug             Start Catalina in a debugger (not available on OS400)"
  671     echo "  debug -security   Debug Catalina with a security manager (not available on OS400)"
  672   else
  673     echo "  debug             Start Catalina in a debugger"
  674     echo "  debug -security   Debug Catalina with a security manager"
  675   fi
  676   echo "  jpda start        Start Catalina under JPDA debugger"
  677   echo "  run               Start Catalina in the current window"
  678   echo "  run -security     Start in the current window with security manager"
  679   echo "  start             Start Catalina in a separate window"
  680   echo "  start -security   Start in a separate window with security manager"
  681   echo "  stop              Stop Catalina, waiting up to 5 seconds for the process to end"
  682   echo "  stop n            Stop Catalina, waiting up to n seconds for the process to end"
  683   echo "  stop -force       Stop Catalina, wait up to 5 seconds and then use kill -KILL if still running"
  684   echo "  stop n -force     Stop Catalina, wait up to n seconds and then use kill -KILL if still running"
  685   echo "  configtest        Run a basic syntax check on server.xml - check exit code for result"
  686   echo "  version           What version of tomcat are you running?"
  687   echo "Note: Waiting for the process to end and use of the -force option require that \$CATALINA_PID is defined"
  688   exit 1
  689 
  690 fi