catalina.50.sh 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. #!/bin/sh
  2. # -----------------------------------------------------------------------------
  3. # Start/Stop Script for the CATALINA Server
  4. #
  5. # Environment Variable Prequisites
  6. #
  7. # CATALINA_HOME May point at your Catalina "build" directory.
  8. #
  9. # CATALINA_BASE (Optional) Base directory for resolving dynamic portions
  10. # of a Catalina installation. If not present, resolves to
  11. # the same directory that CATALINA_HOME points to.
  12. #
  13. # CATALINA_OPTS (Optional) Java runtime options used when the "start",
  14. # "stop", or "run" command is executed.
  15. #
  16. # CATALINA_TMPDIR (Optional) Directory path location of temporary directory
  17. # the JVM should use (java.io.tmpdir). Defaults to
  18. # $CATALINA_BASE/temp.
  19. #
  20. # JAVA_HOME Must point at your Java Development Kit installation.
  21. #
  22. # JAVA_OPTS (Optional) Java runtime options used when the "start",
  23. # "stop", or "run" command is executed.
  24. #
  25. # JPDA_TRANSPORT (Optional) JPDA transport used when the "jpda start"
  26. # command is executed. The default is "dt_socket".
  27. #
  28. # JPDA_ADDRESS (Optional) Java runtime options used when the "jpda start"
  29. # command is executed. The default is 8000.
  30. #
  31. # JSSE_HOME (Optional) May point at your Java Secure Sockets Extension
  32. # (JSSE) installation, whose JAR files will be added to the
  33. # system class path used to start Tomcat.
  34. #
  35. # CATALINA_PID (Optional) Path of the file which should contains the pid
  36. # of catalina startup java process, when start (fork) is used
  37. #
  38. # $Id: catalina.50.sh,v 1.1 2005/03/05 00:29:13 matt Exp $
  39. # -----------------------------------------------------------------------------
  40. # OS specific support. $var _must_ be set to either true or false.
  41. cygwin=false
  42. os400=false
  43. case "`uname`" in
  44. CYGWIN*) cygwin=true;;
  45. OS400*) os400=true;;
  46. esac
  47. # resolve links - $0 may be a softlink
  48. PRG="$0"
  49. while [ -h "$PRG" ]; do
  50. ls=`ls -ld "$PRG"`
  51. link=`expr "$ls" : '.*-> \(.*\)$'`
  52. if expr "$link" : '.*/.*' > /dev/null; then
  53. PRG="$link"
  54. else
  55. PRG=`dirname "$PRG"`/"$link"
  56. fi
  57. done
  58. # Get standard environment variables
  59. PRGDIR=`dirname "$PRG"`
  60. # Only set CATALINA_HOME if not already set
  61. [ -z "$CATALINA_HOME" ] && CATALINA_HOME=`cd "$PRGDIR/.." ; pwd`
  62. if [ -r "$CATALINA_HOME"/bin/setenv.sh ]; then
  63. . "$CATALINA_HOME"/bin/setenv.sh
  64. fi
  65. # For Cygwin, ensure paths are in UNIX format before anything is touched
  66. if $cygwin; then
  67. [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  68. [ -n "$CATALINA_HOME" ] && CATALINA_HOME=`cygpath --unix "$CATALINA_HOME"`
  69. [ -n "$CATALINA_BASE" ] && CATALINA_BASE=`cygpath --unix "$CATALINA_BASE"`
  70. [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
  71. [ -n "$JSSE_HOME" ] && JSSE_HOME=`cygpath --absolute --unix "$JSSE_HOME"`
  72. fi
  73. # For OS400
  74. if $os400; then
  75. # Set job priority to standard for interactive (interactive - 6) by using
  76. # the interactive priority - 6, the helper threads that respond to requests
  77. # will be running at the same priority as interactive jobs.
  78. COMMAND='chgjob job('$JOBNAME') runpty(6)'
  79. system $COMMAND
  80. # Enable multi threading
  81. export QIBM_MULTI_THREADED=Y
  82. fi
  83. # Get standard Java environment variables
  84. if [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then
  85. BASEDIR="$CATALINA_HOME"
  86. . "$CATALINA_HOME"/bin/setclasspath.sh
  87. else
  88. echo "Cannot find $CATALINA_HOME/bin/setclasspath.sh"
  89. echo "This file is needed to run this program"
  90. exit 1
  91. fi
  92. # Add on extra jar files to CLASSPATH
  93. if [ -n "$JSSE_HOME" ]; then
  94. CLASSPATH="$CLASSPATH":"$JSSE_HOME"/lib/jcert.jar:"$JSSE_HOME"/lib/jnet.jar:"$JSSE_HOME"/lib/jsse.jar
  95. fi
  96. CLASSPATH="$CLASSPATH":"$CATALINA_HOME"/bin/bootstrap.jar:"$CATALINA_HOME"/bin/commons-logging-api.jar
  97. if [ -z "$CATALINA_BASE" ] ; then
  98. CATALINA_BASE="$CATALINA_HOME"
  99. fi
  100. if [ -z "$CATALINA_TMPDIR" ] ; then
  101. # Define the java.io.tmpdir to use for Catalina
  102. CATALINA_TMPDIR="$CATALINA_BASE"/temp
  103. fi
  104. # For Cygwin, switch paths to Windows format before running java
  105. if $cygwin; then
  106. JAVA_HOME=`cygpath --absolute --windows "$JAVA_HOME"`
  107. CATALINA_HOME=`cygpath --absolute --windows "$CATALINA_HOME"`
  108. CATALINA_BASE=`cygpath --absolute --windows "$CATALINA_BASE"`
  109. CATALINA_TMPDIR=`cygpath --absolute --windows "$CATALINA_TMPDIR"`
  110. CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  111. [ -n "$JSSE_HOME" ] && JSSE_HOME=`cygpath --absolute --windows "$JSSE_HOME"`
  112. JAVA_ENDORSED_DIRS=`cygpath --path --windows "$JAVA_ENDORSED_DIRS"`
  113. fi
  114. # ----- Execute The Requested Command -----------------------------------------
  115. echo "Using CATALINA_BASE: $CATALINA_BASE"
  116. echo "Using CATALINA_HOME: $CATALINA_HOME"
  117. echo "Using CATALINA_TMPDIR: $CATALINA_TMPDIR"
  118. echo "Using JAVA_HOME: $JAVA_HOME"
  119. if [ "$1" = "jpda" ] ; then
  120. if [ -z "$JPDA_TRANSPORT" ]; then
  121. JPDA_TRANSPORT="dt_socket"
  122. fi
  123. if [ -z "$JPDA_ADDRESS" ]; then
  124. JPDA_ADDRESS="8000"
  125. fi
  126. if [ -z "$JPDA_OPTS" ]; then
  127. JPDA_OPTS="-Xdebug -Xrunjdwp:transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=n"
  128. fi
  129. CATALINA_OPTS="$CATALINA_OPTS $JPDA_OPTS"
  130. shift
  131. fi
  132. if [ "$1" = "debug" ] ; then
  133. if $os400; then
  134. echo "Debug command not available on OS400"
  135. exit 1
  136. else
  137. shift
  138. if [ "$1" = "-security" ] ; then
  139. echo "Using Security Manager"
  140. shift
  141. exec "$_RUNJDB" $JAVA_OPTS $CATALINA_OPTS \
  142. -classpath "$CLASSPATH" \
  143. -sourcepath "$CATALINA_HOME"/../../jakarta-tomcat-catalina/catalina/src/share \
  144. -Djava.security.manager \
  145. -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
  146. -Dcatalina.base="$CATALINA_BASE" \
  147. -Dcatalina.home="$CATALINA_HOME" \
  148. -Djava.io.tmpdir="$CATALINA_TMPDIR" \
  149. org.apache.catalina.startup.Bootstrap "$@" start
  150. else
  151. exec "$_RUNJDB" $JAVA_OPTS $CATALINA_OPTS \
  152. -classpath "$CLASSPATH" \
  153. -sourcepath "$CATALINA_HOME"/../../jakarta-tomcat-catalina/catalina/src/share \
  154. -Dcatalina.base="$CATALINA_BASE" \
  155. -Dcatalina.home="$CATALINA_HOME" \
  156. -Djava.io.tmpdir="$CATALINA_TMPDIR" \
  157. org.apache.catalina.startup.Bootstrap "$@" start
  158. fi
  159. fi
  160. elif [ "$1" = "run" ]; then
  161. shift
  162. if [ "$1" = "-security" ] ; then
  163. echo "Using Security Manager"
  164. shift
  165. exec "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
  166. -classpath "$CLASSPATH" \
  167. -Djava.security.manager \
  168. -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
  169. -Dcatalina.base="$CATALINA_BASE" \
  170. -Dcatalina.home="$CATALINA_HOME" \
  171. -Djava.io.tmpdir="$CATALINA_TMPDIR" \
  172. org.apache.catalina.startup.Bootstrap "$@" start
  173. else
  174. exec "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
  175. -classpath "$CLASSPATH" \
  176. -Dcatalina.base="$CATALINA_BASE" \
  177. -Dcatalina.home="$CATALINA_HOME" \
  178. -Djava.io.tmpdir="$CATALINA_TMPDIR" \
  179. org.apache.catalina.startup.Bootstrap "$@" start
  180. fi
  181. elif [ "$1" = "start" ] ; then
  182. shift
  183. touch "$CATALINA_BASE"/logs/catalina.out
  184. if [ "$1" = "-security" ] ; then
  185. echo "Using Security Manager"
  186. shift
  187. "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
  188. -classpath "$CLASSPATH" \
  189. -Djava.security.manager \
  190. -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
  191. -Dcatalina.base="$CATALINA_BASE" \
  192. -Dcatalina.home="$CATALINA_HOME" \
  193. -Djava.io.tmpdir="$CATALINA_TMPDIR" \
  194. org.apache.catalina.startup.Bootstrap "$@" start \
  195. >> "$CATALINA_BASE"/logs/catalina.out 2>&1 &
  196. if [ ! -z "$CATALINA_PID" ]; then
  197. echo $! > $CATALINA_PID
  198. fi
  199. else
  200. "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
  201. -classpath "$CLASSPATH" \
  202. -Dcatalina.base="$CATALINA_BASE" \
  203. -Dcatalina.home="$CATALINA_HOME" \
  204. -Djava.io.tmpdir="$CATALINA_TMPDIR" \
  205. org.apache.catalina.startup.Bootstrap "$@" start \
  206. >> "$CATALINA_BASE"/logs/catalina.out 2>&1 &
  207. if [ ! -z "$CATALINA_PID" ]; then
  208. echo $! > $CATALINA_PID
  209. fi
  210. fi
  211. elif [ "$1" = "stop" ] ; then
  212. shift
  213. FORCE=0
  214. if [ "$1" = "-force" ]; then
  215. shift
  216. FORCE=1
  217. fi
  218. "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
  219. -classpath "$CLASSPATH" \
  220. -Dcatalina.base="$CATALINA_BASE" \
  221. -Dcatalina.home="$CATALINA_HOME" \
  222. -Djava.io.tmpdir="$CATALINA_TMPDIR" \
  223. org.apache.catalina.startup.Bootstrap "$@" stop
  224. if [ $FORCE -eq 1 ]; then
  225. if [ ! -z "$CATALINA_PID" ]; then
  226. echo "Killing: `cat $CATALINA_PID`"
  227. kill -9 `cat $CATALINA_PID`
  228. fi
  229. fi
  230. elif [ "$1" = "version" ] ; then
  231. "$_RUNJAVA" \
  232. -classpath "$CATALINA_HOME/server/lib/catalina.jar" \
  233. org.apache.catalina.util.ServerInfo
  234. else
  235. echo "Usage: catalina.sh ( commands ... )"
  236. echo "commands:"
  237. if $os400; then
  238. echo " debug Start Catalina in a debugger (not available on OS400)"
  239. echo " debug -security Debug Catalina with a security manager (not available on OS400)"
  240. else
  241. echo " debug Start Catalina in a debugger"
  242. echo " debug -security Debug Catalina with a security manager"
  243. fi
  244. echo " jpda start Start Catalina under JPDA debugger"
  245. echo " run Start Catalina in the current window"
  246. echo " run -security Start in the current window with security manager"
  247. echo " start Start Catalina in a separate window"
  248. echo " start -security Start in a separate window with security manager"
  249. echo " stop Stop Catalina"
  250. echo " stop -force Stop Catalina (followed by kill -KILL)"
  251. echo " version What version of tomcat are you running?"
  252. exit 1
  253. fi