catalina.sh 25 KB

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