karaf 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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. realpath() {
  19. OURPWD=${PWD}
  20. cd "$(dirname "${1}")" || exit 2
  21. LINK=$(ls -l "$(basename "${1}")" | awk -F"-> " '{print $2}')
  22. while [ "${LINK}" ]; do
  23. echo "link: ${LINK}" >&2
  24. cd "$(dirname "${LINK}")" || exit 2
  25. LINK=$(ls -l "$(basename "${1}")" | awk -F"-> " '{print $2}')
  26. done
  27. REALPATH="${PWD}/$(basename "${1}")"
  28. cd "${OURPWD}" || exit 2
  29. echo "${REALPATH}"
  30. }
  31. REALNAME=$(realpath "$0")
  32. DIRNAME=$(dirname "${REALNAME}")
  33. PROGNAME=$(basename "${REALNAME}")
  34. #
  35. # Sourcing environment settings for karaf similar to tomcats setenv
  36. #
  37. KARAF_SCRIPT="karaf"
  38. export KARAF_SCRIPT
  39. if [ -f "${DIRNAME}/setenv" ]; then
  40. . "${DIRNAME}/setenv"
  41. fi
  42. #
  43. # Set up some easily accessible MIN/MAX params for JVM mem usage
  44. #
  45. if [ "x${JAVA_MIN_MEM}" = "x" ]; then
  46. JAVA_MIN_MEM=128M
  47. export JAVA_MIN_MEM
  48. fi
  49. if [ "x${JAVA_MAX_MEM}" = "x" ]; then
  50. JAVA_MAX_MEM=512M
  51. export JAVA_MAX_MEM
  52. fi
  53. #
  54. # Check the mode that initiated the script
  55. #
  56. if [ "x${1}" != "x" ]; then
  57. MODE=${1}
  58. fi
  59. warn() {
  60. echo "${PROGNAME}: $*"
  61. }
  62. die() {
  63. warn "$*"
  64. exit 1
  65. }
  66. forceNoRoot() {
  67. # If configured, prevent execution as root
  68. if [ "${KARAF_NOROOT}" ] && [ "$(id -u)" -eq 0 ]; then
  69. echo "Do not run as root!"
  70. exit 2
  71. fi
  72. }
  73. detectOS() {
  74. # OS specific support (must be 'true' or 'false').
  75. cygwin=false;
  76. darwin=false;
  77. aix=false;
  78. os400=false;
  79. case "$(uname)" in
  80. CYGWIN*)
  81. cygwin=true
  82. ;;
  83. Darwin*)
  84. darwin=true
  85. ;;
  86. AIX*)
  87. aix=true
  88. ;;
  89. OS400*)
  90. os400=true
  91. ;;
  92. esac
  93. # For AIX, set an environment variable
  94. if ${aix}; then
  95. export LDR_CNTRL=MAXDATA=0xB0000000@DSA
  96. echo ${LDR_CNTRL}
  97. fi
  98. }
  99. unlimitFD() {
  100. # Use the maximum available, or set MAX_FD != -1 to use that
  101. if [ "x${MAX_FD}" = "x" ]; then
  102. MAX_FD="maximum"
  103. fi
  104. # Increase the maximum file descriptors if we can
  105. if [ "x$(command -v ulimit)" != "x" ] && [ "${os400}" = "false" ] ; then
  106. if [ "${MAX_FD}" = "maximum" ] || [ "${MAX_FD}" = "max" ]; then
  107. MAX_FD_LIMIT=$(ulimit -H -n)
  108. if [ $? -eq 0 ]; then
  109. # use the system max
  110. MAX_FD="${MAX_FD_LIMIT}"
  111. else
  112. warn "Could not query system maximum file descriptor limit: ${MAX_FD_LIMIT}"
  113. fi
  114. fi
  115. if [ "${MAX_FD}" != 'unlimited' ]; then
  116. ulimit -n "${MAX_FD}" > /dev/null
  117. if [ $? -ne 0 ]; then
  118. warn "Could not set maximum file descriptor limit: ${MAX_FD}"
  119. fi
  120. fi
  121. fi
  122. }
  123. locateHome() {
  124. if [ "x${KARAF_HOME}" = "x" ]; then
  125. # In POSIX shells, CDPATH may cause cd to write to stdout
  126. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
  127. # KARAF_HOME is not provided, fall back to default
  128. KARAF_HOME=$(cd "${DIRNAME}/.." || exit 2; pwd)
  129. fi
  130. if [ ! -d "${KARAF_HOME}" ]; then
  131. die "KARAF_HOME is not valid: ${KARAF_HOME}"
  132. fi
  133. }
  134. locateBase() {
  135. if [ "x${KARAF_BASE}" != "x" ]; then
  136. if [ ! -d "${KARAF_BASE}" ]; then
  137. die "KARAF_BASE is not valid: ${KARAF_BASE}"
  138. fi
  139. else
  140. KARAF_BASE=${KARAF_HOME}
  141. fi
  142. }
  143. locateData() {
  144. if [ "x${KARAF_DATA}" != "x" ]; then
  145. if [ ! -d "${KARAF_DATA}" ]; then
  146. die "KARAF_DATA is not valid: ${KARAF_DATA}"
  147. fi
  148. else
  149. KARAF_DATA=${KARAF_BASE}/data
  150. fi
  151. }
  152. locateEtc() {
  153. if [ "x${KARAF_ETC}" != "x" ]; then
  154. if [ ! -d "${KARAF_ETC}" ]; then
  155. die "KARAF_ETC is not valid: ${KARAF_ETC}"
  156. fi
  157. else
  158. KARAF_ETC=${KARAF_BASE}/etc
  159. fi
  160. }
  161. setupNativePath() {
  162. # Support for loading native libraries
  163. LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${KARAF_BASE}/lib:${KARAF_HOME}/lib"
  164. # For Cygwin, set PATH from LD_LIBRARY_PATH
  165. if ${cygwin}; then
  166. LD_LIBRARY_PATH=$(cygpath --path --windows "${LD_LIBRARY_PATH}")
  167. PATH="${PATH};${LD_LIBRARY_PATH}"
  168. export PATH
  169. fi
  170. export LD_LIBRARY_PATH
  171. }
  172. pathCanonical() {
  173. dst="${1}"
  174. while [ -h "${dst}" ] ; do
  175. ls=$(ls -ld "${dst}")
  176. link=$(expr "${ls}" : '.*-> \(.*\)$')
  177. if expr "${link}" : '/.*' > /dev/null; then
  178. dst="${link}"
  179. else
  180. dst="$(dirname "${dst}")/${link}"
  181. fi
  182. done
  183. bas=$(basename "${dst}")
  184. dir=$(dirname "${dst}")
  185. if [ "${bas}" != "${dir}" ]; then
  186. dst="$(pathCanonical "${dir}")/${bas}"
  187. fi
  188. echo "${dst}" | sed -e 's#//#/#g' -e 's#/./#/#g' -e 's#/[^/]*/../#/#g'
  189. }
  190. locateJava() {
  191. # Setup the Java Virtual Machine
  192. if ${cygwin} ; then
  193. [ -n "${JAVA}" ] && JAVA=$(cygpath --unix "${JAVA}")
  194. [ -n "${JAVA_HOME}" ] && JAVA_HOME=$(cygpath --unix "${JAVA_HOME}")
  195. fi
  196. if [ "x${JAVA_HOME}" = "x" ] && [ "${darwin}" = "true" ]; then
  197. JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"
  198. fi
  199. if [ "x${JAVA}" = "x" ] && [ -r /etc/gentoo-release ] ; then
  200. JAVA_HOME=$(java-config --jre-home)
  201. fi
  202. if [ "x${JAVA}" = "x" ]; then
  203. if [ "x${JAVA_HOME}" != "x" ]; then
  204. if [ ! -d "${JAVA_HOME}" ]; then
  205. die "JAVA_HOME is not valid: ${JAVA_HOME}"
  206. fi
  207. JAVA="${JAVA_HOME}/bin/java"
  208. else
  209. warn "JAVA_HOME not set; results may vary"
  210. JAVA=$(command -v java)
  211. if [ "x${JAVA}" = "x" ]; then
  212. die "java command not found"
  213. fi
  214. fi
  215. fi
  216. if [ "x${JAVA_HOME}" = "x" ]; then
  217. JAVA_HOME="$(dirname "$(dirname "$(pathCanonical "${JAVA}")")")"
  218. fi
  219. }
  220. detectJVM() {
  221. #echo "$(${JAVA} -version)"
  222. # This service should call $(java -version),
  223. # read stdout, and look for hints
  224. if ${JAVA} -version 2>&1 | grep "^IBM" ; then
  225. JVM_VENDOR="IBM"
  226. # on OS/400, java -version does not contain IBM explicitly
  227. elif ${os400}; then
  228. JVM_VENDOR="IBM"
  229. else
  230. JVM_VENDOR="SUN"
  231. fi
  232. # echo "JVM vendor is ${JVM_VENDOR}"
  233. }
  234. checkJvmVersion() {
  235. # echo "$(${JAVA} -version)"
  236. VERSION=$("${JAVA}" -version 2>&1 | egrep '"([0-9].[0-9]\..*[0-9]).*"' | awk '{print substr($3,2,length($3)-2)}' | awk '{print substr($1, 3, 3)}' | sed -e 's;\.;;g')
  237. if [ "x${VERSION}" = "x" ]; then
  238. VERSION=90
  239. fi
  240. if [ "${VERSION}" -lt "60" ]; then
  241. echo "JVM must be greater than 1.6"
  242. exit 1;
  243. fi
  244. }
  245. setupDebugOptions() {
  246. if [ "x${JAVA_OPTS}" = "x" ]; then
  247. JAVA_OPTS="${DEFAULT_JAVA_OPTS}"
  248. fi
  249. export JAVA_OPTS
  250. if [ "x${EXTRA_JAVA_OPTS}" != "x" ]; then
  251. JAVA_OPTS="${JAVA_OPTS} ${EXTRA_JAVA_OPTS}"
  252. fi
  253. # Set Debug options if enabled
  254. if [ "x${KARAF_DEBUG}" != "x" ]; then
  255. # Ignore DEBUG in case of stop, client, or status mode
  256. if [ "x${MODE}" = "xstop" ]; then
  257. return
  258. fi
  259. if [ "x${MODE}" = "xclient" ]; then
  260. return
  261. fi
  262. if [ "x${MODE}" = "xstatus" ]; then
  263. return
  264. fi
  265. # Use the defaults if JAVA_DEBUG_OPTS was not set
  266. if [ "x${JAVA_DEBUG_OPTS}" = "x" ]; then
  267. JAVA_DEBUG_OPTS="${DEFAULT_JAVA_DEBUG_OPTS}"
  268. fi
  269. JAVA_OPTS="${JAVA_DEBUG_OPTS} ${JAVA_OPTS}"
  270. warn "Enabling Java debug options: ${JAVA_DEBUG_OPTS}"
  271. fi
  272. }
  273. setupDefaults() {
  274. DEFAULT_JAVA_OPTS="-Xms${JAVA_MIN_MEM} -Xmx${JAVA_MAX_MEM} -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass "
  275. #Set the JVM_VENDOR specific JVM flags
  276. if [ "${JVM_VENDOR}" = "SUN" ]; then
  277. # permgen was removed in Java 8
  278. VERSION=$("${JAVA}" -version 2>&1 | egrep '"([0-9].[0-9]\..*[0-9]).*"' | awk '{print substr($3,2,length($3)-2)}' | awk '{print substr($1, 3, 3)}' | sed -e 's;\.;;g')
  279. if [ "x${VERSION}" = "x" ]; then
  280. VERSION=90
  281. fi
  282. if [ "${VERSION}" -lt "80" ]; then
  283. # Check some easily accessible MIN/MAX params for JVM mem usage
  284. if [ "x${JAVA_PERM_MEM}" != "x" ]; then
  285. DEFAULT_JAVA_OPTS="${DEFAULT_JAVA_OPTS} -XX:PermSize=${JAVA_PERM_MEM}"
  286. fi
  287. if [ "x${JAVA_MAX_PERM_MEM}" != "x" ]; then
  288. DEFAULT_JAVA_OPTS="${DEFAULT_JAVA_OPTS} -XX:MaxPermSize=${JAVA_MAX_PERM_MEM}"
  289. fi
  290. fi
  291. DEFAULT_JAVA_OPTS="-server ${DEFAULT_JAVA_OPTS} -Dcom.sun.management.jmxremote"
  292. elif [ "${JVM_VENDOR}" = "IBM" ]; then
  293. if ${os400}; then
  294. DEFAULT_JAVA_OPTS="${DEFAULT_JAVA_OPTS}"
  295. elif ${aix}; then
  296. DEFAULT_JAVA_OPTS="-Xverify:none -Xdump:heap -Xlp ${DEFAULT_JAVA_OPTS}"
  297. else
  298. DEFAULT_JAVA_OPTS="-Xverify:none ${DEFAULT_JAVA_OPTS}"
  299. fi
  300. fi
  301. # Add the jars in the lib dir
  302. for file in "${KARAF_HOME}"/lib/boot/*.jar
  303. do
  304. if [ -z "${CLASSPATH}" ]; then
  305. CLASSPATH="${file}"
  306. else
  307. CLASSPATH="${CLASSPATH}:${file}"
  308. fi
  309. done
  310. DEFAULT_JAVA_DEBUG_PORT="5005"
  311. if [ "x${JAVA_DEBUG_PORT}" = "x" ]; then
  312. JAVA_DEBUG_PORT="${DEFAULT_JAVA_DEBUG_PORT}"
  313. fi
  314. DEFAULT_JAVA_DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=${JAVA_DEBUG_PORT}"
  315. ##
  316. ## TODO: Move to conf/profiler/yourkit.{sh|cmd}
  317. ##
  318. # Uncomment to enable YourKit profiling
  319. #DEFAULT_JAVA_DEBUG_OPTS="-Xrunyjpagent"
  320. }
  321. checkRootInstance() {
  322. ROOT_INSTANCE_RUNNING=false
  323. if [ -f "${KARAF_HOME}/instances/instance.properties" ];
  324. then
  325. ROOT_INSTANCE_PID=$(sed -n -e '/item.0.pid/ s/.*\= *//p' "${KARAF_HOME}/instances/instance.properties")
  326. ROOT_INSTANCE_NAME=$(sed -n -e '/item.0.name/ s/.*\= *//p' "${KARAF_HOME}/instances/instance.properties")
  327. if [ "${ROOT_INSTANCE_PID}" -ne "0" ]; then
  328. if ps p "${ROOT_INSTANCE_PID}" > /dev/null
  329. then
  330. ROOT_INSTANCE_RUNNING=true
  331. fi
  332. fi
  333. fi
  334. }
  335. init() {
  336. # Prevent root execution if configured
  337. forceNoRoot
  338. # Determine if there is special OS handling we must perform
  339. detectOS
  340. # Unlimit the number of file descriptors if possible
  341. unlimitFD
  342. # Locate the Karaf home directory
  343. locateHome
  344. # Locate the Karaf base directory
  345. locateBase
  346. # Locate the Karaf data directory
  347. locateData
  348. # Locate the Karaf etc directory
  349. locateEtc
  350. # Setup the native library path
  351. setupNativePath
  352. # Locate the Java VM to execute
  353. locateJava
  354. # Determine the JVM vendor
  355. detectJVM
  356. # Determine the JVM version >= 1.6
  357. checkJvmVersion
  358. # Check if a root instance is already running
  359. checkRootInstance
  360. # Setup default options
  361. setupDefaults
  362. # Install debug options
  363. setupDebugOptions
  364. }
  365. run() {
  366. OPTS="-Dkaraf.startLocalConsole=true -Dkaraf.startRemoteShell=true"
  367. MAIN=org.apache.karaf.main.Main
  368. CHECK_ROOT_INSTANCE_RUNNING=true
  369. while [ "${1}" != "" ]; do
  370. case ${1} in
  371. 'clean')
  372. rm -rf "${KARAF_DATA:?}"
  373. shift
  374. ;;
  375. 'debug')
  376. if [ "x${JAVA_DEBUG_OPTS}" = "x" ]; then
  377. JAVA_DEBUG_OPTS="${DEFAULT_JAVA_DEBUG_OPTS}"
  378. fi
  379. JAVA_OPTS="${JAVA_DEBUG_OPTS} ${JAVA_OPTS}"
  380. shift
  381. ;;
  382. 'status')
  383. MAIN=org.apache.karaf.main.Status
  384. CHECK_ROOT_INSTANCE_RUNNING=false
  385. shift
  386. ;;
  387. 'stop')
  388. MAIN=org.apache.karaf.main.Stop
  389. CHECK_ROOT_INSTANCE_RUNNING=false
  390. shift
  391. ;;
  392. 'console')
  393. CHECK_ROOT_INSTANCE_RUNNING=false
  394. shift
  395. ;;
  396. 'server')
  397. OPTS="-Dkaraf.startLocalConsole=false -Dkaraf.startRemoteShell=true"
  398. shift
  399. ;;
  400. 'daemon')
  401. OPTS="-Dkaraf.startLocalConsole=false -Dkaraf.startRemoteShell=true"
  402. KARAF_DAEMON="true"
  403. KARAF_EXEC="exec"
  404. shift
  405. ;;
  406. 'client')
  407. OPTS="-Dkaraf.startLocalConsole=true -Dkaraf.startRemoteShell=false"
  408. CHECK_ROOT_INSTANCE_RUNNING=false
  409. shift
  410. ;;
  411. *)
  412. break
  413. ;;
  414. esac
  415. done
  416. JAVA_ENDORSED_DIRS="${JAVA_HOME}/jre/lib/endorsed:${JAVA_HOME}/lib/endorsed:${KARAF_HOME}/lib/endorsed"
  417. JAVA_EXT_DIRS="${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext:${KARAF_HOME}/lib/ext"
  418. if ${cygwin}; then
  419. KARAF_HOME=$(cygpath --path --windows "${KARAF_HOME}")
  420. KARAF_BASE=$(cygpath --path --windows "${KARAF_BASE}")
  421. KARAF_DATA=$(cygpath --path --windows "${KARAF_DATA}")
  422. KARAF_ETC=$(cygpath --path --windows "${KARAF_ETC}")
  423. if [ ! -z "${CLASSPATH}" ]; then
  424. CLASSPATH=$(cygpath --path --windows "${CLASSPATH}")
  425. fi
  426. JAVA_HOME=$(cygpath --path --windows "${JAVA_HOME}")
  427. JAVA_ENDORSED_DIRS=$(cygpath --path --windows "${JAVA_ENDORSED_DIRS}")
  428. JAVA_EXT_DIRS=$(cygpath --path --windows "${JAVA_EXT_DIRS}")
  429. fi
  430. cd "${KARAF_BASE}" || exit 2
  431. if [ -z "${KARAF_EXEC}" ]; then
  432. KARAF_EXEC=""
  433. fi
  434. while true; do
  435. # When users want to update the lib version of, they just need to create
  436. # a lib.next directory and on the new restart, it will replace the current lib directory.
  437. if [ -d "${KARAF_HOME:?}/lib.next" ] ; then
  438. echo "Updating libs..."
  439. rm -rf "${KARAF_HOME:?}/lib"
  440. mv -f "${KARAF_HOME:?}/lib.next" "${KARAF_HOME}/lib"
  441. fi
  442. # Ensure the log directory exists
  443. # We may need to have a place to redirect stdout/stderr
  444. if [ ! -d "${KARAF_DATA}/log" ]; then
  445. mkdir -p "${KARAF_DATA}/log"
  446. fi
  447. if [ "${ROOT_INSTANCE_RUNNING}" = "false" ] || [ "${CHECK_ROOT_INSTANCE_RUNNING}" = "false" ] ; then
  448. if [ "${VERSION}" -gt "80" ]; then
  449. ${KARAF_EXEC} "${JAVA}" ${JAVA_OPTS} \
  450. --add-exports=java.base/sun.net.www.protocol.http=ALL-UNNAMED \
  451. --add-exports=java.base/sun.net.www.protocol.https=ALL-UNNAMED \
  452. --add-exports=java.base/sun.net.www.protocol.jar=ALL-UNNAMED \
  453. --add-exports=java.xml.bind/com.sun.xml.internal.bind.v2.runtime=ALL-UNNAMED \
  454. --add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED \
  455. --add-exports=jdk.naming.rmi/com.sun.jndi.url.rmi=ALL-UNNAMED \
  456. --add-modules java.annotations.common,java.corba,java.transaction,java.xml.bind,java.xml.ws \
  457. -Dkaraf.instances="${KARAF_HOME}/instances" \
  458. -Dkaraf.home="${KARAF_HOME}" \
  459. -Dkaraf.base="${KARAF_BASE}" \
  460. -Dkaraf.data="${KARAF_DATA}" \
  461. -Dkaraf.etc="${KARAF_ETC}" \
  462. -Dkaraf.restart.jvm.supported=true \
  463. -Djava.io.tmpdir="${KARAF_DATA}/tmp" \
  464. -Djava.util.logging.config.file="${KARAF_BASE}/etc/java.util.logging.properties" \
  465. ${KARAF_SYSTEM_OPTS} \
  466. ${KARAF_OPTS} \
  467. ${OPTS} \
  468. -classpath "${CLASSPATH}" \
  469. ${MAIN} "$@"
  470. else
  471. ${KARAF_EXEC} "${JAVA}" ${JAVA_OPTS} \
  472. -Djava.endorsed.dirs="${JAVA_ENDORSED_DIRS}" \
  473. -Djava.ext.dirs="${JAVA_EXT_DIRS}" \
  474. -Dkaraf.instances="${KARAF_HOME}/instances" \
  475. -Dkaraf.home="${KARAF_HOME}" \
  476. -Dkaraf.base="${KARAF_BASE}" \
  477. -Dkaraf.data="${KARAF_DATA}" \
  478. -Dkaraf.etc="${KARAF_ETC}" \
  479. -Dkaraf.restart.jvm.supported=true \
  480. -Djava.io.tmpdir="${KARAF_DATA}/tmp" \
  481. -Djava.util.logging.config.file="${KARAF_BASE}/etc/java.util.logging.properties" \
  482. ${KARAF_SYSTEM_OPTS} \
  483. ${KARAF_OPTS} \
  484. ${OPTS} \
  485. -classpath "${CLASSPATH}" \
  486. ${MAIN} "$@"
  487. fi
  488. else
  489. die "There is a Root instance already running with name ${ROOT_INSTANCE_NAME} and pid ${ROOT_INSTANCE_PID}"
  490. fi
  491. KARAF_RC=$?
  492. if [ ${KARAF_DAEMON} ] ; then
  493. exit ${KARAF_RC}
  494. else
  495. if [ "${KARAF_RC}" -eq 10 ]; then
  496. echo "Restarting JVM..."
  497. else
  498. exit ${KARAF_RC}
  499. fi
  500. fi
  501. done
  502. }
  503. main() {
  504. init
  505. run "$@"
  506. }
  507. main "$@"