catalina.sh 21 KB

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