You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

inc 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. #!/bin/sh
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one or more
  4. # contributor license agreements. See the NOTICE file distributed with
  5. # this work for additional information regarding copyright ownership.
  6. # The ASF licenses this file to You under the Apache License, Version 2.0
  7. # (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. warn() {
  19. echo "${PROGNAME}: $*"
  20. }
  21. die() {
  22. warn "$*"
  23. exit 1
  24. }
  25. detectOS() {
  26. # OS specific support (must be 'true' or 'false').
  27. cygwin=false;
  28. mingw=false;
  29. darwin=false;
  30. aix=false;
  31. os400=false;
  32. hpux=false;
  33. solaris=false;
  34. case "$(uname)" in
  35. CYGWIN*)
  36. cygwin=true
  37. ;;
  38. MINGW*)
  39. mingw=true
  40. ;;
  41. Darwin*)
  42. darwin=true
  43. ;;
  44. AIX*)
  45. aix=true
  46. # For AIX, set an environment variable
  47. export LDR_CNTRL=MAXDATA=0xB0000000@DSA
  48. echo ${LDR_CNTRL}
  49. ;;
  50. OS400*)
  51. os400=true
  52. ;;
  53. HP-UX*)
  54. hpux=true
  55. # For HP-UX, set an environment variable
  56. export PS_PREFIX="UNIX95= "
  57. echo "${PS_PREFIX}"
  58. ;;
  59. SunOS*)
  60. solaris=true
  61. ;;
  62. esac
  63. }
  64. unlimitFD() {
  65. # Use the maximum available, or set MAX_FD != -1 to use that
  66. if [ "x${MAX_FD}" = "x" ]; then
  67. MAX_FD="maximum"
  68. fi
  69. # Increase the maximum file descriptors if we can
  70. if [ "x$(command -v ulimit)" != "x" ] && [ "${os400}" = "false" ] ; then
  71. if [ "${MAX_FD}" = "maximum" ] || [ "${MAX_FD}" = "max" ]; then
  72. MAX_FD_LIMIT=$(ulimit -H -n)
  73. if [ $? -eq 0 ]; then
  74. # use the system max
  75. MAX_FD="${MAX_FD_LIMIT}"
  76. else
  77. warn "Could not query system maximum file descriptor limit: ${MAX_FD_LIMIT}"
  78. fi
  79. fi
  80. if [ "${MAX_FD}" != 'unlimited' ]; then
  81. ulimit -n "${MAX_FD}" > /dev/null
  82. if [ $? -ne 0 ]; then
  83. warn "Could not set maximum file descriptor limit: ${MAX_FD}"
  84. fi
  85. fi
  86. fi
  87. }
  88. locateHome() {
  89. if [ "x${KARAF_HOME}" != "x" ]; then
  90. warn "Ignoring predefined value for KARAF_HOME"
  91. unset KARAF_HOME
  92. fi
  93. if [ "x${KARAF_HOME}" = "x" ]; then
  94. # In POSIX shells, CDPATH may cause cd to write to stdout
  95. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
  96. # KARAF_HOME is not provided, fall back to default
  97. KARAF_HOME=$(cd "${DIRNAME}/.." || exit 2; pwd)
  98. fi
  99. if [ ! -d "${KARAF_HOME}" ]; then
  100. die "KARAF_HOME is not valid: ${KARAF_HOME}"
  101. fi
  102. }
  103. locateBase() {
  104. if [ "x${KARAF_BASE}" != "x" ]; then
  105. if [ ! -d "${KARAF_BASE}" ]; then
  106. die "KARAF_BASE is not valid: ${KARAF_BASE}"
  107. fi
  108. else
  109. KARAF_BASE=${KARAF_HOME}
  110. fi
  111. }
  112. locateData() {
  113. if [ "x${KARAF_DATA}" != "x" ]; then
  114. if [ ! -d "${KARAF_DATA}" ]; then
  115. die "KARAF_DATA is not valid: ${KARAF_DATA}"
  116. fi
  117. else
  118. KARAF_DATA=${KARAF_BASE}/data
  119. fi
  120. }
  121. locateEtc() {
  122. if [ "x${KARAF_ETC}" != "x" ]; then
  123. if [ ! -d "${KARAF_ETC}" ]; then
  124. die "KARAF_ETC is not valid: ${KARAF_ETC}"
  125. fi
  126. else
  127. KARAF_ETC=${KARAF_BASE}/etc
  128. fi
  129. }
  130. setupNativePath() {
  131. # Support for loading native libraries
  132. LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${KARAF_BASE}/lib:${KARAF_HOME}/lib"
  133. # For Cygwin, set PATH from LD_LIBRARY_PATH
  134. if ${cygwin}; then
  135. LD_LIBRARY_PATH=$(cygpath --path --windows "${LD_LIBRARY_PATH}")
  136. PATH="${PATH};${LD_LIBRARY_PATH}"
  137. export PATH
  138. fi
  139. export LD_LIBRARY_PATH
  140. }
  141. pathCanonical() {
  142. dst="${1}"
  143. while [ -h "${dst}" ] ; do
  144. ls=$(ls -ld "${dst}")
  145. link=$(expr "${ls}" : '.*-> \(.*\)$')
  146. if expr "${link}" : '/.*' > /dev/null; then
  147. dst="${link}"
  148. else
  149. dst="$(dirname "${dst}")/${link}"
  150. fi
  151. done
  152. bas=$(basename "${dst}")
  153. dir=$(dirname "${dst}")
  154. if [ "${bas}" != "${dir}" ]; then
  155. dst="$(pathCanonical "${dir}")/${bas}"
  156. fi
  157. echo "${dst}" | sed -e 's#//#/#g' -e 's#/./#/#g' -e 's#/[^/]*/../#/#g'
  158. }
  159. locateJava() {
  160. # Setup the Java Virtual Machine
  161. if ${cygwin} ; then
  162. [ -n "${JAVA}" ] && JAVA=$(cygpath --unix "${JAVA}")
  163. [ -n "${JAVA_HOME}" ] && JAVA_HOME=$(cygpath --unix "${JAVA_HOME}")
  164. fi
  165. if [ "x${JAVA_HOME}" = "x" ] && [ "${darwin}" = "true" ]; then
  166. JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"
  167. fi
  168. if [ "x${JAVA}" = "x" ] && [ -r /etc/gentoo-release ] ; then
  169. JAVA_HOME=$(java-config --jre-home)
  170. fi
  171. if [ "x${JAVA}" = "x" ]; then
  172. if [ "x${JAVA_HOME}" != "x" ]; then
  173. if [ ! -d "${JAVA_HOME}" ]; then
  174. die "JAVA_HOME is not valid: ${JAVA_HOME}"
  175. fi
  176. JAVA="${JAVA_HOME}/bin/java"
  177. else
  178. warn "JAVA_HOME not set; results may vary"
  179. JAVA=$(command -v java)
  180. if [ "x${JAVA}" = "x" ]; then
  181. die "java command not found"
  182. fi
  183. fi
  184. fi
  185. if [ "x${JAVA_HOME}" = "x" ]; then
  186. JAVA_HOME="$(dirname "$(dirname "$(pathCanonical "${JAVA}")")")"
  187. fi
  188. }
  189. detectJVM() {
  190. # This service should call $(java -version),
  191. # read stdout, and look for hints
  192. if "${JAVA}" -version 2>&1 | grep "^IBM" ; then
  193. JVM_VENDOR="IBM"
  194. # on OS/400, java -version does not contain IBM explicitly
  195. elif ${os400}; then
  196. JVM_VENDOR="IBM"
  197. else
  198. JVM_VENDOR="SUN"
  199. fi
  200. # echo "JVM vendor is ${JVM_VENDOR}"
  201. }
  202. checkJvmVersion() {
  203. # Use in priority xpg4 awk or nawk on SunOS as standard awk is outdated
  204. AWK=awk
  205. if ${solaris}; then
  206. if [ -x /usr/xpg4/bin/awk ]; then
  207. AWK=/usr/xpg4/bin/awk
  208. elif [ -x /usr/bin/nawk ]; then
  209. AWK=/usr/bin/nawk
  210. fi
  211. fi
  212. VERSION=$("${JAVA}" -version 2>&1 | ${AWK} -F '"' '/version/ {print $2}' | sed -e 's/_.*//g; s/^1\.//g; s/\..*//g; s/-.*//g;')
  213. # java must be at least version 8
  214. if [ "${VERSION}" -lt "8" ]; then
  215. die "JVM must be greater than 1.8"
  216. fi
  217. }
  218. setupDebugOptions() {
  219. if [ "x${JAVA_OPTS}" = "x" ]; then
  220. JAVA_OPTS="${DEFAULT_JAVA_OPTS}"
  221. fi
  222. export JAVA_OPTS
  223. if [ "x${EXTRA_JAVA_OPTS}" != "x" ]; then
  224. JAVA_OPTS="${JAVA_OPTS} ${EXTRA_JAVA_OPTS}"
  225. fi
  226. # Set Debug options if enabled
  227. if [ "x${KARAF_DEBUG}" != "x" ]; then
  228. # Use the defaults if JAVA_DEBUG_OPTS was not set
  229. if [ "x${JAVA_DEBUG_OPTS}" = "x" ]; then
  230. JAVA_DEBUG_OPTS="${DEFAULT_JAVA_DEBUG_OPTS}"
  231. fi
  232. JAVA_OPTS="${JAVA_DEBUG_OPTS} ${JAVA_OPTS}"
  233. warn "Enabling Java debug options: ${JAVA_DEBUG_OPTS}"
  234. fi
  235. }
  236. setupDefaults() {
  237. #
  238. # Set up some easily accessible MIN/MAX params for JVM mem usage
  239. #
  240. if [ "x${JAVA_MIN_MEM}" = "x" ]; then
  241. JAVA_MIN_MEM=128M
  242. export JAVA_MIN_MEM
  243. fi
  244. if [ "x${JAVA_MAX_MEM}" = "x" ]; then
  245. JAVA_MAX_MEM=512M
  246. export JAVA_MAX_MEM
  247. fi
  248. DEFAULT_JAVA_OPTS="-Xms${JAVA_MIN_MEM} -Xmx${JAVA_MAX_MEM} -XX:+UnlockDiagnosticVMOptions "
  249. #Set the JVM_VENDOR specific JVM flags
  250. if [ "${JVM_VENDOR}" = "SUN" ]; then
  251. DEFAULT_JAVA_OPTS="${DEFAULT_JAVA_OPTS} -Dcom.sun.management.jmxremote"
  252. elif [ "${JVM_VENDOR}" = "IBM" ]; then
  253. if ${os400}; then
  254. DEFAULT_JAVA_OPTS="${DEFAULT_JAVA_OPTS}"
  255. elif ${aix}; then
  256. DEFAULT_JAVA_OPTS="-Xverify:none -Xdump:heap -Xlp ${DEFAULT_JAVA_OPTS}"
  257. else
  258. DEFAULT_JAVA_OPTS="-Xverify:none ${DEFAULT_JAVA_OPTS}"
  259. fi
  260. fi
  261. DEFAULT_JAVA_DEBUG_PORT="5005"
  262. if [ "x${JAVA_DEBUG_PORT}" = "x" ]; then
  263. JAVA_DEBUG_PORT="${DEFAULT_JAVA_DEBUG_PORT}"
  264. fi
  265. DEFAULT_JAVA_DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=${JAVA_DEBUG_PORT}"
  266. DEFAULT_JAVA_DEBUGS_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=${JAVA_DEBUG_PORT}"
  267. ##
  268. ## TODO: Move to conf/profiler/yourkit.{sh|cmd}
  269. ##
  270. # Uncomment to enable YourKit profiling
  271. #DEFAULT_JAVA_DEBUG_OPTS="-Xrunyjpagent"
  272. }
  273. convertPaths() {
  274. if $cygwin; then
  275. if [ ! -z "${KARAF_HOME}" ]; then
  276. KARAF_HOME=$(cygpath --path --windows "${KARAF_HOME}")
  277. fi
  278. if [ ! -z "${KARAF_BASE}" ]; then
  279. KARAF_BASE=$(cygpath --path --windows "${KARAF_BASE}")
  280. fi
  281. if [ ! -z "${KARAF_DATA}" ]; then
  282. KARAF_DATA=$(cygpath --path --windows "${KARAF_DATA}")
  283. fi
  284. if [ ! -z "${KARAF_ETC}" ]; then
  285. KARAF_ETC=$(cygpath --path --windows "${KARAF_ETC}")
  286. fi
  287. if [ ! -z "${CLASSPATH}" ]; then
  288. CLASSPATH=$(cygpath --path --windows "${CLASSPATH}")
  289. fi
  290. fi
  291. }