Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

663 рядки
24 KiB

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