catalina.sh 23 KB

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