Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 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 | # ----------------------------------------------------------------------------- |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 19 | # Control Script for the CATALINA Server |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 20 | # |
| 21 | # Environment Variable Prerequisites |
| 22 | # |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 23 | # 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 Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 26 | # 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", |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 37 | # "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 Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 42 | # |
| 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 | # |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 50 | # 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 Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 53 | # |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 54 | # 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 Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 60 | # |
| 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. |
刘洪青 | a78cd38 | 2018-03-01 14:48:24 +0800 | [diff] [blame] | 65 | # Note that Java 9 no longer supports this feature. |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 66 | # Defaults to $CATALINA_HOME/endorsed. |
| 67 | # |
| 68 | # JPDA_TRANSPORT (Optional) JPDA transport used when the "jpda start" |
| 69 | # command is executed. The default is "dt_socket". |
| 70 | # |
| 71 | # JPDA_ADDRESS (Optional) Java runtime options used when the "jpda start" |
| 72 | # command is executed. The default is 8000. |
| 73 | # |
| 74 | # JPDA_SUSPEND (Optional) Java runtime options used when the "jpda start" |
| 75 | # command is executed. Specifies whether JVM should suspend |
| 76 | # execution immediately after startup. Default is "n". |
| 77 | # |
| 78 | # JPDA_OPTS (Optional) Java runtime options used when the "jpda start" |
| 79 | # command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS, |
| 80 | # and JPDA_SUSPEND are ignored. Thus, all required jpda |
| 81 | # options MUST be specified. The default is: |
| 82 | # |
| 83 | # -agentlib:jdwp=transport=$JPDA_TRANSPORT, |
| 84 | # address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND |
| 85 | # |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 86 | # JSSE_OPTS (Optional) Java runtime options used to control the TLS |
| 87 | # implementation when JSSE is used. Default is: |
| 88 | # "-Djdk.tls.ephemeralDHKeySize=2048" |
| 89 | # |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 90 | # CATALINA_PID (Optional) Path of the file which should contains the pid |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 91 | # of the catalina startup java process, when start (fork) is |
| 92 | # used |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 93 | # |
| 94 | # LOGGING_CONFIG (Optional) Override Tomcat's logging config file |
| 95 | # Example (all one line) |
| 96 | # LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties" |
| 97 | # |
| 98 | # LOGGING_MANAGER (Optional) Override Tomcat's logging manager |
| 99 | # Example (all one line) |
| 100 | # LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 101 | # |
| 102 | # USE_NOHUP (Optional) If set to the string true the start command will |
| 103 | # use nohup so that the Tomcat process will ignore any hangup |
| 104 | # signals. Default is "false" unless running on HP-UX in which |
| 105 | # case the default is "true" |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 106 | # ----------------------------------------------------------------------------- |
| 107 | |
| 108 | # OS specific support. $var _must_ be set to either true or false. |
| 109 | cygwin=false |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 110 | darwin=false |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 111 | os400=false |
| 112 | hpux=false |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 113 | case "`uname`" in |
| 114 | CYGWIN*) cygwin=true;; |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 115 | Darwin*) darwin=true;; |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 116 | OS400*) os400=true;; |
| 117 | HP-UX*) hpux=true;; |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 118 | esac |
| 119 | |
| 120 | # resolve links - $0 may be a softlink |
| 121 | PRG="$0" |
| 122 | |
| 123 | while [ -h "$PRG" ]; do |
| 124 | ls=`ls -ld "$PRG"` |
| 125 | link=`expr "$ls" : '.*-> \(.*\)$'` |
| 126 | if expr "$link" : '/.*' > /dev/null; then |
| 127 | PRG="$link" |
| 128 | else |
| 129 | PRG=`dirname "$PRG"`/"$link" |
| 130 | fi |
| 131 | done |
| 132 | |
| 133 | # Get standard environment variables |
| 134 | PRGDIR=`dirname "$PRG"` |
| 135 | |
| 136 | # Only set CATALINA_HOME if not already set |
| 137 | [ -z "$CATALINA_HOME" ] && CATALINA_HOME=`cd "$PRGDIR/.." >/dev/null; pwd` |
| 138 | |
| 139 | # Copy CATALINA_BASE from CATALINA_HOME if not already set |
| 140 | [ -z "$CATALINA_BASE" ] && CATALINA_BASE="$CATALINA_HOME" |
| 141 | |
| 142 | # Ensure that any user defined CLASSPATH variables are not used on startup, |
| 143 | # but allow them to be specified in setenv.sh, in rare case when it is needed. |
| 144 | CLASSPATH= |
| 145 | |
| 146 | if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then |
| 147 | . "$CATALINA_BASE/bin/setenv.sh" |
| 148 | elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then |
| 149 | . "$CATALINA_HOME/bin/setenv.sh" |
| 150 | fi |
| 151 | |
| 152 | # For Cygwin, ensure paths are in UNIX format before anything is touched |
| 153 | if $cygwin; then |
| 154 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` |
| 155 | [ -n "$JRE_HOME" ] && JRE_HOME=`cygpath --unix "$JRE_HOME"` |
| 156 | [ -n "$CATALINA_HOME" ] && CATALINA_HOME=`cygpath --unix "$CATALINA_HOME"` |
| 157 | [ -n "$CATALINA_BASE" ] && CATALINA_BASE=`cygpath --unix "$CATALINA_BASE"` |
| 158 | [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"` |
| 159 | fi |
| 160 | |
| 161 | # For OS400 |
| 162 | if $os400; then |
| 163 | # Set job priority to standard for interactive (interactive - 6) by using |
| 164 | # the interactive priority - 6, the helper threads that respond to requests |
| 165 | # will be running at the same priority as interactive jobs. |
| 166 | COMMAND='chgjob job('$JOBNAME') runpty(6)' |
| 167 | system $COMMAND |
| 168 | |
| 169 | # Enable multi threading |
| 170 | export QIBM_MULTI_THREADED=Y |
| 171 | fi |
| 172 | |
| 173 | # Get standard Java environment variables |
| 174 | if $os400; then |
| 175 | # -r will Only work on the os400 if the files are: |
| 176 | # 1. owned by the user |
| 177 | # 2. owned by the PRIMARY group of the user |
| 178 | # this will not work if the user belongs in secondary groups |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 179 | . "$CATALINA_HOME"/bin/setclasspath.sh |
| 180 | else |
| 181 | if [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 182 | . "$CATALINA_HOME"/bin/setclasspath.sh |
| 183 | else |
| 184 | echo "Cannot find $CATALINA_HOME/bin/setclasspath.sh" |
| 185 | echo "This file is needed to run this program" |
| 186 | exit 1 |
| 187 | fi |
| 188 | fi |
| 189 | |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 190 | # Add on extra jar files to CLASSPATH |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 191 | if [ ! -z "$CLASSPATH" ] ; then |
| 192 | CLASSPATH="$CLASSPATH": |
| 193 | fi |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 194 | CLASSPATH="$CLASSPATH""$CATALINA_HOME"/bin/bootstrap.jar |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 195 | |
| 196 | if [ -z "$CATALINA_OUT" ] ; then |
| 197 | CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out |
| 198 | fi |
| 199 | |
| 200 | if [ -z "$CATALINA_TMPDIR" ] ; then |
| 201 | # Define the java.io.tmpdir to use for Catalina |
| 202 | CATALINA_TMPDIR="$CATALINA_BASE"/temp |
| 203 | fi |
| 204 | |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 205 | # Add tomcat-juli.jar to classpath |
| 206 | # tomcat-juli.jar can be over-ridden per instance |
| 207 | if [ -r "$CATALINA_BASE/bin/tomcat-juli.jar" ] ; then |
| 208 | CLASSPATH=$CLASSPATH:$CATALINA_BASE/bin/tomcat-juli.jar |
| 209 | else |
| 210 | CLASSPATH=$CLASSPATH:$CATALINA_HOME/bin/tomcat-juli.jar |
| 211 | fi |
| 212 | |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 213 | # Bugzilla 37848: When no TTY is available, don't output to console |
| 214 | have_tty=0 |
| 215 | if [ "`tty`" != "not a tty" ]; then |
| 216 | have_tty=1 |
| 217 | fi |
| 218 | |
| 219 | # For Cygwin, switch paths to Windows format before running java |
| 220 | if $cygwin; then |
| 221 | JAVA_HOME=`cygpath --absolute --windows "$JAVA_HOME"` |
| 222 | JRE_HOME=`cygpath --absolute --windows "$JRE_HOME"` |
| 223 | CATALINA_HOME=`cygpath --absolute --windows "$CATALINA_HOME"` |
| 224 | CATALINA_BASE=`cygpath --absolute --windows "$CATALINA_BASE"` |
| 225 | CATALINA_TMPDIR=`cygpath --absolute --windows "$CATALINA_TMPDIR"` |
| 226 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` |
| 227 | JAVA_ENDORSED_DIRS=`cygpath --path --windows "$JAVA_ENDORSED_DIRS"` |
| 228 | fi |
| 229 | |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 230 | if [ -z "$JSSE_OPTS" ] ; then |
| 231 | JSSE_OPTS="-Djdk.tls.ephemeralDHKeySize=2048" |
| 232 | fi |
| 233 | JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS" |
| 234 | |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 235 | # Set juli LogManager config file if it is present and an override has not been issued |
| 236 | if [ -z "$LOGGING_CONFIG" ]; then |
| 237 | if [ -r "$CATALINA_BASE"/conf/logging.properties ]; then |
| 238 | LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties" |
| 239 | else |
| 240 | # Bugzilla 45585 |
| 241 | LOGGING_CONFIG="-Dnop" |
| 242 | fi |
| 243 | fi |
| 244 | |
| 245 | if [ -z "$LOGGING_MANAGER" ]; then |
| 246 | LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" |
| 247 | fi |
| 248 | |
刘洪青 | a78cd38 | 2018-03-01 14:48:24 +0800 | [diff] [blame] | 249 | # Java 9 no longer supports the java.endorsed.dirs |
| 250 | # system property. Only try to use it if |
| 251 | # JAVA_ENDORSED_DIRS was explicitly set |
| 252 | # or CATALINA_HOME/endorsed exists. |
| 253 | ENDORSED_PROP=ignore.endorsed.dirs |
| 254 | if [ -n "$JAVA_ENDORSED_DIRS" ]; then |
| 255 | ENDORSED_PROP=java.endorsed.dirs |
| 256 | fi |
| 257 | if [ -d "$CATALINA_HOME/endorsed" ]; then |
| 258 | ENDORSED_PROP=java.endorsed.dirs |
| 259 | fi |
| 260 | |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 261 | # Uncomment the following line to make the umask available when using the |
| 262 | # org.apache.catalina.security.SecurityListener |
| 263 | #JAVA_OPTS="$JAVA_OPTS -Dorg.apache.catalina.security.SecurityListener.UMASK=`umask`" |
| 264 | |
| 265 | if [ -z "$USE_NOHUP" ]; then |
| 266 | if $hpux; then |
| 267 | USE_NOHUP="true" |
| 268 | else |
| 269 | USE_NOHUP="false" |
| 270 | fi |
| 271 | fi |
| 272 | unset _NOHUP |
| 273 | if [ "$USE_NOHUP" = "true" ]; then |
| 274 | _NOHUP=nohup |
| 275 | fi |
| 276 | |
刘洪青 | a78cd38 | 2018-03-01 14:48:24 +0800 | [diff] [blame] | 277 | # Add the JAVA 9 specific start-up parameters required by Tomcat |
| 278 | JDK_JAVA_OPTIONS="$JDK_JAVA_OPTIONS --add-opens=java.base/java.lang=ALL-UNNAMED" |
| 279 | JDK_JAVA_OPTIONS="$JDK_JAVA_OPTIONS --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED" |
| 280 | export JDK_JAVA_OPTIONS |
| 281 | |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 282 | # ----- Execute The Requested Command ----------------------------------------- |
| 283 | |
| 284 | # Bugzilla 37848: only output this if we have a TTY |
| 285 | if [ $have_tty -eq 1 ]; then |
| 286 | echo "Using CATALINA_BASE: $CATALINA_BASE" |
| 287 | echo "Using CATALINA_HOME: $CATALINA_HOME" |
| 288 | echo "Using CATALINA_TMPDIR: $CATALINA_TMPDIR" |
| 289 | if [ "$1" = "debug" ] ; then |
| 290 | echo "Using JAVA_HOME: $JAVA_HOME" |
| 291 | else |
| 292 | echo "Using JRE_HOME: $JRE_HOME" |
| 293 | fi |
| 294 | echo "Using CLASSPATH: $CLASSPATH" |
| 295 | if [ ! -z "$CATALINA_PID" ]; then |
| 296 | echo "Using CATALINA_PID: $CATALINA_PID" |
| 297 | fi |
| 298 | fi |
| 299 | |
| 300 | if [ "$1" = "jpda" ] ; then |
| 301 | if [ -z "$JPDA_TRANSPORT" ]; then |
| 302 | JPDA_TRANSPORT="dt_socket" |
| 303 | fi |
| 304 | if [ -z "$JPDA_ADDRESS" ]; then |
| 305 | JPDA_ADDRESS="8000" |
| 306 | fi |
| 307 | if [ -z "$JPDA_SUSPEND" ]; then |
| 308 | JPDA_SUSPEND="n" |
| 309 | fi |
| 310 | if [ -z "$JPDA_OPTS" ]; then |
| 311 | JPDA_OPTS="-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND" |
| 312 | fi |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 313 | CATALINA_OPTS="$JPDA_OPTS $CATALINA_OPTS" |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 314 | shift |
| 315 | fi |
| 316 | |
| 317 | if [ "$1" = "debug" ] ; then |
| 318 | if $os400; then |
| 319 | echo "Debug command not available on OS400" |
| 320 | exit 1 |
| 321 | else |
| 322 | shift |
| 323 | if [ "$1" = "-security" ] ; then |
| 324 | if [ $have_tty -eq 1 ]; then |
| 325 | echo "Using Security Manager" |
| 326 | fi |
| 327 | shift |
| 328 | exec "$_RUNJDB" "$LOGGING_CONFIG" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ |
刘洪青 | a78cd38 | 2018-03-01 14:48:24 +0800 | [diff] [blame] | 329 | -D$ENDORSED_PROP="$JAVA_ENDORSED_DIRS" \ |
| 330 | -classpath "$CLASSPATH" \ |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 331 | -sourcepath "$CATALINA_HOME"/../../java \ |
| 332 | -Djava.security.manager \ |
| 333 | -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \ |
| 334 | -Dcatalina.base="$CATALINA_BASE" \ |
| 335 | -Dcatalina.home="$CATALINA_HOME" \ |
| 336 | -Djava.io.tmpdir="$CATALINA_TMPDIR" \ |
| 337 | org.apache.catalina.startup.Bootstrap "$@" start |
| 338 | else |
| 339 | exec "$_RUNJDB" "$LOGGING_CONFIG" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ |
刘洪青 | a78cd38 | 2018-03-01 14:48:24 +0800 | [diff] [blame] | 340 | -D$ENDORSED_PROP="$JAVA_ENDORSED_DIRS" \ |
| 341 | -classpath "$CLASSPATH" \ |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 342 | -sourcepath "$CATALINA_HOME"/../../java \ |
| 343 | -Dcatalina.base="$CATALINA_BASE" \ |
| 344 | -Dcatalina.home="$CATALINA_HOME" \ |
| 345 | -Djava.io.tmpdir="$CATALINA_TMPDIR" \ |
| 346 | org.apache.catalina.startup.Bootstrap "$@" start |
| 347 | fi |
| 348 | fi |
| 349 | |
| 350 | elif [ "$1" = "run" ]; then |
| 351 | |
| 352 | shift |
| 353 | if [ "$1" = "-security" ] ; then |
| 354 | if [ $have_tty -eq 1 ]; then |
| 355 | echo "Using Security Manager" |
| 356 | fi |
| 357 | shift |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 358 | eval exec "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ |
刘洪青 | a78cd38 | 2018-03-01 14:48:24 +0800 | [diff] [blame] | 359 | -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \ |
| 360 | -classpath "\"$CLASSPATH\"" \ |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 361 | -Djava.security.manager \ |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 362 | -Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \ |
| 363 | -Dcatalina.base="\"$CATALINA_BASE\"" \ |
| 364 | -Dcatalina.home="\"$CATALINA_HOME\"" \ |
| 365 | -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \ |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 366 | org.apache.catalina.startup.Bootstrap "$@" start |
| 367 | else |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 368 | eval exec "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ |
刘洪青 | a78cd38 | 2018-03-01 14:48:24 +0800 | [diff] [blame] | 369 | -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \ |
| 370 | -classpath "\"$CLASSPATH\"" \ |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 371 | -Dcatalina.base="\"$CATALINA_BASE\"" \ |
| 372 | -Dcatalina.home="\"$CATALINA_HOME\"" \ |
| 373 | -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \ |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 374 | org.apache.catalina.startup.Bootstrap "$@" start |
| 375 | fi |
| 376 | |
| 377 | elif [ "$1" = "start" ] ; then |
| 378 | |
| 379 | if [ ! -z "$CATALINA_PID" ]; then |
| 380 | if [ -f "$CATALINA_PID" ]; then |
| 381 | if [ -s "$CATALINA_PID" ]; then |
| 382 | echo "Existing PID file found during start." |
| 383 | if [ -r "$CATALINA_PID" ]; then |
| 384 | PID=`cat "$CATALINA_PID"` |
| 385 | ps -p $PID >/dev/null 2>&1 |
| 386 | if [ $? -eq 0 ] ; then |
| 387 | echo "Tomcat appears to still be running with PID $PID. Start aborted." |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 388 | echo "If the following process is not a Tomcat process, remove the PID file and try again:" |
| 389 | ps -f -p $PID |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 390 | exit 1 |
| 391 | else |
| 392 | echo "Removing/clearing stale PID file." |
| 393 | rm -f "$CATALINA_PID" >/dev/null 2>&1 |
| 394 | if [ $? != 0 ]; then |
| 395 | if [ -w "$CATALINA_PID" ]; then |
| 396 | cat /dev/null > "$CATALINA_PID" |
| 397 | else |
| 398 | echo "Unable to remove or clear stale PID file. Start aborted." |
| 399 | exit 1 |
| 400 | fi |
| 401 | fi |
| 402 | fi |
| 403 | else |
| 404 | echo "Unable to read PID file. Start aborted." |
| 405 | exit 1 |
| 406 | fi |
| 407 | else |
| 408 | rm -f "$CATALINA_PID" >/dev/null 2>&1 |
| 409 | if [ $? != 0 ]; then |
| 410 | if [ ! -w "$CATALINA_PID" ]; then |
| 411 | echo "Unable to remove or write to empty PID file. Start aborted." |
| 412 | exit 1 |
| 413 | fi |
| 414 | fi |
| 415 | fi |
| 416 | fi |
| 417 | fi |
| 418 | |
| 419 | shift |
| 420 | touch "$CATALINA_OUT" |
| 421 | if [ "$1" = "-security" ] ; then |
| 422 | if [ $have_tty -eq 1 ]; then |
| 423 | echo "Using Security Manager" |
| 424 | fi |
| 425 | shift |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 426 | eval $_NOHUP "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ |
刘洪青 | a78cd38 | 2018-03-01 14:48:24 +0800 | [diff] [blame] | 427 | -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \ |
| 428 | -classpath "\"$CLASSPATH\"" \ |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 429 | -Djava.security.manager \ |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 430 | -Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \ |
| 431 | -Dcatalina.base="\"$CATALINA_BASE\"" \ |
| 432 | -Dcatalina.home="\"$CATALINA_HOME\"" \ |
| 433 | -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \ |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 434 | org.apache.catalina.startup.Bootstrap "$@" start \ |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 435 | >> "$CATALINA_OUT" 2>&1 "&" |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 436 | |
| 437 | else |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 438 | eval $_NOHUP "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ |
刘洪青 | a78cd38 | 2018-03-01 14:48:24 +0800 | [diff] [blame] | 439 | -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \ |
| 440 | -classpath "\"$CLASSPATH\"" \ |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 441 | -Dcatalina.base="\"$CATALINA_BASE\"" \ |
| 442 | -Dcatalina.home="\"$CATALINA_HOME\"" \ |
| 443 | -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \ |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 444 | org.apache.catalina.startup.Bootstrap "$@" start \ |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 445 | >> "$CATALINA_OUT" 2>&1 "&" |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 446 | |
| 447 | fi |
| 448 | |
| 449 | if [ ! -z "$CATALINA_PID" ]; then |
| 450 | echo $! > "$CATALINA_PID" |
| 451 | fi |
| 452 | |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 453 | echo "Tomcat started." |
| 454 | |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 455 | elif [ "$1" = "stop" ] ; then |
| 456 | |
| 457 | shift |
| 458 | |
| 459 | SLEEP=5 |
| 460 | if [ ! -z "$1" ]; then |
| 461 | echo $1 | grep "[^0-9]" >/dev/null 2>&1 |
| 462 | if [ $? -gt 0 ]; then |
| 463 | SLEEP=$1 |
| 464 | shift |
| 465 | fi |
| 466 | fi |
| 467 | |
| 468 | FORCE=0 |
| 469 | if [ "$1" = "-force" ]; then |
| 470 | shift |
| 471 | FORCE=1 |
| 472 | fi |
| 473 | |
| 474 | if [ ! -z "$CATALINA_PID" ]; then |
| 475 | if [ -f "$CATALINA_PID" ]; then |
| 476 | if [ -s "$CATALINA_PID" ]; then |
| 477 | kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1 |
| 478 | if [ $? -gt 0 ]; then |
| 479 | echo "PID file found but no matching process was found. Stop aborted." |
| 480 | exit 1 |
| 481 | fi |
| 482 | else |
| 483 | echo "PID file is empty and has been ignored." |
| 484 | fi |
| 485 | else |
| 486 | echo "\$CATALINA_PID was set but the specified file does not exist. Is Tomcat running? Stop aborted." |
| 487 | exit 1 |
| 488 | fi |
| 489 | fi |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 490 | |
| 491 | eval "\"$_RUNJAVA\"" $LOGGING_MANAGER $JAVA_OPTS \ |
刘洪青 | a78cd38 | 2018-03-01 14:48:24 +0800 | [diff] [blame] | 492 | -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \ |
| 493 | -classpath "\"$CLASSPATH\"" \ |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 494 | -Dcatalina.base="\"$CATALINA_BASE\"" \ |
| 495 | -Dcatalina.home="\"$CATALINA_HOME\"" \ |
| 496 | -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \ |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 497 | org.apache.catalina.startup.Bootstrap "$@" stop |
| 498 | |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 499 | # stop failed. Shutdown port disabled? Try a normal kill. |
| 500 | if [ $? != 0 ]; then |
| 501 | if [ ! -z "$CATALINA_PID" ]; then |
| 502 | echo "The stop command failed. Attempting to signal the process to stop through OS signal." |
| 503 | kill -15 `cat "$CATALINA_PID"` >/dev/null 2>&1 |
| 504 | fi |
| 505 | fi |
| 506 | |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 507 | if [ ! -z "$CATALINA_PID" ]; then |
| 508 | if [ -f "$CATALINA_PID" ]; then |
| 509 | while [ $SLEEP -ge 0 ]; do |
| 510 | kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1 |
| 511 | if [ $? -gt 0 ]; then |
| 512 | rm -f "$CATALINA_PID" >/dev/null 2>&1 |
| 513 | if [ $? != 0 ]; then |
| 514 | if [ -w "$CATALINA_PID" ]; then |
| 515 | cat /dev/null > "$CATALINA_PID" |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 516 | # If Tomcat has stopped don't try and force a stop with an empty PID file |
| 517 | FORCE=0 |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 518 | else |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 519 | echo "The PID file could not be removed or cleared." |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 520 | fi |
| 521 | fi |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 522 | echo "Tomcat stopped." |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 523 | break |
| 524 | fi |
| 525 | if [ $SLEEP -gt 0 ]; then |
| 526 | sleep 1 |
| 527 | fi |
| 528 | if [ $SLEEP -eq 0 ]; then |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 529 | echo "Tomcat did not stop in time." |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 530 | if [ $FORCE -eq 0 ]; then |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 531 | echo "PID file was not removed." |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 532 | fi |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 533 | echo "To aid diagnostics a thread dump has been written to standard out." |
| 534 | kill -3 `cat "$CATALINA_PID"` |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 535 | fi |
| 536 | SLEEP=`expr $SLEEP - 1 ` |
| 537 | done |
| 538 | fi |
| 539 | fi |
| 540 | |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 541 | KILL_SLEEP_INTERVAL=5 |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 542 | if [ $FORCE -eq 1 ]; then |
| 543 | if [ -z "$CATALINA_PID" ]; then |
| 544 | echo "Kill failed: \$CATALINA_PID not set" |
| 545 | else |
| 546 | if [ -f "$CATALINA_PID" ]; then |
| 547 | PID=`cat "$CATALINA_PID"` |
| 548 | echo "Killing Tomcat with the PID: $PID" |
| 549 | kill -9 $PID |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 550 | while [ $KILL_SLEEP_INTERVAL -ge 0 ]; do |
| 551 | kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1 |
| 552 | if [ $? -gt 0 ]; then |
| 553 | rm -f "$CATALINA_PID" >/dev/null 2>&1 |
| 554 | if [ $? != 0 ]; then |
| 555 | if [ -w "$CATALINA_PID" ]; then |
| 556 | cat /dev/null > "$CATALINA_PID" |
| 557 | else |
| 558 | echo "The PID file could not be removed." |
| 559 | fi |
| 560 | fi |
| 561 | echo "The Tomcat process has been killed." |
| 562 | break |
| 563 | fi |
| 564 | if [ $KILL_SLEEP_INTERVAL -gt 0 ]; then |
| 565 | sleep 1 |
| 566 | fi |
| 567 | KILL_SLEEP_INTERVAL=`expr $KILL_SLEEP_INTERVAL - 1 ` |
| 568 | done |
| 569 | if [ $KILL_SLEEP_INTERVAL -lt 0 ]; then |
| 570 | echo "Tomcat has not been killed completely yet. The process might be waiting on some system call or might be UNINTERRUPTIBLE." |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 571 | fi |
| 572 | fi |
| 573 | fi |
| 574 | fi |
| 575 | |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 576 | elif [ "$1" = "configtest" ] ; then |
| 577 | |
| 578 | eval "\"$_RUNJAVA\"" $LOGGING_MANAGER $JAVA_OPTS \ |
刘洪青 | a78cd38 | 2018-03-01 14:48:24 +0800 | [diff] [blame] | 579 | -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \ |
| 580 | -classpath "\"$CLASSPATH\"" \ |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 581 | -Dcatalina.base="\"$CATALINA_BASE\"" \ |
| 582 | -Dcatalina.home="\"$CATALINA_HOME\"" \ |
| 583 | -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \ |
| 584 | org.apache.catalina.startup.Bootstrap configtest |
| 585 | result=$? |
| 586 | if [ $result -ne 0 ]; then |
| 587 | echo "Configuration error detected!" |
| 588 | fi |
| 589 | exit $result |
| 590 | |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 591 | elif [ "$1" = "version" ] ; then |
| 592 | |
| 593 | "$_RUNJAVA" \ |
| 594 | -classpath "$CATALINA_HOME/lib/catalina.jar" \ |
| 595 | org.apache.catalina.util.ServerInfo |
| 596 | |
| 597 | else |
| 598 | |
| 599 | echo "Usage: catalina.sh ( commands ... )" |
| 600 | echo "commands:" |
| 601 | if $os400; then |
| 602 | echo " debug Start Catalina in a debugger (not available on OS400)" |
| 603 | echo " debug -security Debug Catalina with a security manager (not available on OS400)" |
| 604 | else |
| 605 | echo " debug Start Catalina in a debugger" |
| 606 | echo " debug -security Debug Catalina with a security manager" |
| 607 | fi |
| 608 | echo " jpda start Start Catalina under JPDA debugger" |
| 609 | echo " run Start Catalina in the current window" |
| 610 | echo " run -security Start in the current window with security manager" |
| 611 | echo " start Start Catalina in a separate window" |
| 612 | echo " start -security Start in a separate window with security manager" |
| 613 | echo " stop Stop Catalina, waiting up to 5 seconds for the process to end" |
| 614 | echo " stop n Stop Catalina, waiting up to n seconds for the process to end" |
| 615 | echo " stop -force Stop Catalina, wait up to 5 seconds and then use kill -KILL if still running" |
| 616 | echo " stop n -force Stop Catalina, wait up to n seconds and then use kill -KILL if still running" |
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame] | 617 | echo " configtest Run a basic syntax check on server.xml - check exit code for result" |
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 618 | echo " version What version of tomcat are you running?" |
| 619 | echo "Note: Waiting for the process to end and use of the -force option require that \$CATALINA_PID is defined" |
| 620 | exit 1 |
| 621 | |
| 622 | fi |