tool-wrapper.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. # Wrapper script for command line tools
  18. #
  19. # Environment Variable Prerequisites
  20. #
  21. # CATALINA_HOME May point at your Catalina "build" directory.
  22. #
  23. # TOOL_OPTS (Optional) Java runtime options.
  24. #
  25. # JAVA_HOME Must point at your Java Development Kit installation.
  26. # Using JRE_HOME instead works as well.
  27. #
  28. # JRE_HOME Must point at your Java Runtime installation.
  29. # Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME
  30. # are both set, JRE_HOME is used.
  31. #
  32. # JAVA_OPTS (Optional) Java runtime options.
  33. #
  34. # JAVA_ENDORSED_DIRS (Optional) Lists of of colon separated directories
  35. # containing some jars in order to allow replacement of APIs
  36. # created outside of the JCP (i.e. DOM and SAX from W3C).
  37. # It can also be used to update the XML parser implementation.
  38. # This is only supported for Java <= 8.
  39. # Defaults to $CATALINA_HOME/endorsed.
  40. # -----------------------------------------------------------------------------
  41. # OS specific support. $var _must_ be set to either true or false.
  42. cygwin=false
  43. darwin=false
  44. os400=false
  45. case "`uname`" in
  46. CYGWIN*) cygwin=true;;
  47. Darwin*) darwin=true;;
  48. OS400*) os400=true;;
  49. esac
  50. # resolve links - $0 may be a softlink
  51. PRG="$0"
  52. while [ -h "$PRG" ]; do
  53. ls=`ls -ld "$PRG"`
  54. link=`expr "$ls" : '.*-> \(.*\)$'`
  55. if expr "$link" : '/.*' > /dev/null; then
  56. PRG="$link"
  57. else
  58. PRG=`dirname "$PRG"`/"$link"
  59. fi
  60. done
  61. # Get standard environment variables
  62. PRGDIR=`dirname "$PRG"`
  63. # Only set CATALINA_HOME if not already set
  64. [ -z "$CATALINA_HOME" ] && CATALINA_HOME=`cd "$PRGDIR/.." >/dev/null; pwd`
  65. # Ensure that any user defined CLASSPATH variables are not used on startup,
  66. # but allow them to be specified in setenv.sh, in rare case when it is needed.
  67. CLASSPATH=
  68. if [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
  69. . "$CATALINA_HOME/bin/setenv.sh"
  70. fi
  71. # For Cygwin, ensure paths are in UNIX format before anything is touched
  72. if $cygwin; then
  73. [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  74. [ -n "$JRE_HOME" ] && JRE_HOME=`cygpath --unix "$JRE_HOME"`
  75. [ -n "$CATALINA_HOME" ] && CATALINA_HOME=`cygpath --unix "$CATALINA_HOME"`
  76. [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
  77. fi
  78. # For OS400
  79. if $os400; then
  80. # Set job priority to standard for interactive (interactive - 6) by using
  81. # the interactive priority - 6, the helper threads that respond to requests
  82. # will be running at the same priority as interactive jobs.
  83. COMMAND='chgjob job('$JOBNAME') runpty(6)'
  84. system $COMMAND
  85. # Enable multi threading
  86. export QIBM_MULTI_THREADED=Y
  87. fi
  88. # Get standard Java environment variables
  89. if $os400; then
  90. # -r will Only work on the os400 if the files are:
  91. # 1. owned by the user
  92. # 2. owned by the PRIMARY group of the user
  93. # this will not work if the user belongs in secondary groups
  94. . "$CATALINA_HOME"/bin/setclasspath.sh
  95. else
  96. if [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then
  97. . "$CATALINA_HOME"/bin/setclasspath.sh
  98. else
  99. echo "Cannot find $CATALINA_HOME/bin/setclasspath.sh"
  100. echo "This file is needed to run this program"
  101. exit 1
  102. fi
  103. fi
  104. # Add on extra jar files to CLASSPATH
  105. if [ ! -z "$CLASSPATH" ] ; then
  106. CLASSPATH="$CLASSPATH":
  107. fi
  108. CLASSPATH="$CLASSPATH""$CATALINA_HOME"/bin/bootstrap.jar:"$CATALINA_HOME"/bin/tomcat-juli.jar:"$CATALINA_HOME"/lib/servlet-api.jar:"$CATALINA_HOME"/lib/tomcat-util.jar
  109. # For Cygwin, switch paths to Windows format before running java
  110. if $cygwin; then
  111. JAVA_HOME=`cygpath --absolute --windows "$JAVA_HOME"`
  112. JRE_HOME=`cygpath --absolute --windows "$JRE_HOME"`
  113. CATALINA_HOME=`cygpath --absolute --windows "$CATALINA_HOME"`
  114. CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  115. [ -n "$JAVA_ENDORSED_DIRS" ] && JAVA_ENDORSED_DIRS=`cygpath --path --windows "$JAVA_ENDORSED_DIRS"`
  116. fi
  117. # Java 9 no longer supports the java.endorsed.dirs
  118. # system property. Only try to use it if
  119. # JAVA_ENDORSED_DIRS was explicitly set
  120. # or CATALINA_HOME/endorsed exists.
  121. ENDORSED_PROP=ignore.endorsed.dirs
  122. if [ -n "$JAVA_ENDORSED_DIRS" ]; then
  123. ENDORSED_PROP=java.endorsed.dirs
  124. fi
  125. if [ -d "$CATALINA_HOME/endorsed" ]; then
  126. ENDORSED_PROP=java.endorsed.dirs
  127. fi
  128. JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
  129. # ----- Execute The Requested Command -----------------------------------------
  130. eval exec "\"$_RUNJAVA\"" "$JAVA_OPTS" "$TOOL_OPTS" \
  131. -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
  132. -classpath "\"$CLASSPATH\"" \
  133. -Dcatalina.home="\"$CATALINA_HOME\"" \
  134. org.apache.catalina.startup.Tool "$@"