start 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. cd "$(dirname "${LINK}")" || exit 2
  24. LINK=$(ls -l "$(basename "${1}")" | awk -F"-> " '{print $2}')
  25. done
  26. REALPATH="${PWD}/$(basename "${1}")"
  27. cd "${OURPWD}" || exit 2
  28. echo "${REALPATH}"
  29. }
  30. REALNAME=$(realpath "$0")
  31. DIRNAME=$(dirname "${REALNAME}")
  32. PROGNAME=$(basename "${REALNAME}")
  33. #
  34. # Sourcing environment settings for karaf similar to tomcats setenv
  35. #
  36. KARAF_SCRIPT="start"
  37. export KARAF_SCRIPT
  38. if [ -f "$DIRNAME/setenv" ]; then
  39. . "$DIRNAME/setenv"
  40. fi
  41. warn() {
  42. echo "${PROGNAME}: $*"
  43. }
  44. die() {
  45. warn "$*"
  46. exit 1
  47. }
  48. detectOS() {
  49. # OS specific support (must be 'true' or 'false').
  50. cygwin=false;
  51. darwin=false;
  52. aix=false;
  53. os400=false;
  54. case "`uname`" in
  55. CYGWIN*)
  56. cygwin=true
  57. ;;
  58. Darwin*)
  59. darwin=true
  60. ;;
  61. AIX*)
  62. aix=true
  63. ;;
  64. OS400*)
  65. os400=true
  66. ;;
  67. esac
  68. # For AIX, set an environment variable
  69. if $aix; then
  70. export LDR_CNTRL=MAXDATA=0xB0000000@DSA
  71. echo $LDR_CNTRL
  72. fi
  73. }
  74. locateHome() {
  75. if [ "x$KARAF_HOME" != "x" ]; then
  76. warn "Ignoring predefined value for KARAF_HOME"
  77. fi
  78. # In POSIX shells, CDPATH may cause cd to write to stdout
  79. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
  80. KARAF_HOME=`cd $DIRNAME/..; pwd`
  81. if [ ! -d "$KARAF_HOME" ]; then
  82. die "KARAF_HOME is not valid: $KARAF_HOME"
  83. fi
  84. }
  85. locateBase() {
  86. if [ "x$KARAF_BASE" != "x" ]; then
  87. if [ ! -d "$KARAF_BASE" ]; then
  88. die "KARAF_BASE is not valid: $KARAF_BASE"
  89. fi
  90. else
  91. KARAF_BASE=$KARAF_HOME
  92. fi
  93. }
  94. locateData() {
  95. if [ "x$KARAF_DATA" != "x" ]; then
  96. if [ ! -d "$KARAF_DATA" ]; then
  97. die "KARAF_DATA is not valid: $KARAF_DATA"
  98. fi
  99. else
  100. KARAF_DATA=$KARAF_BASE/data
  101. fi
  102. }
  103. locateEtc() {
  104. if [ "x$KARAF_ETC" != "x" ]; then
  105. if [ ! -d "$KARAF_ETC" ]; then
  106. die "KARAF_ETC is not valid: $KARAF_ETC"
  107. fi
  108. else
  109. KARAF_ETC=$KARAF_BASE/etc
  110. fi
  111. }
  112. enableRedirect() {
  113. if [ "x$KARAF_REDIRECT" != "x" ]; then
  114. warn "Redirecting Karaf output to $KARAF_REDIRECT"
  115. else
  116. KARAF_REDIRECT="/dev/null"
  117. fi
  118. }
  119. init() {
  120. # Determine if there is special OS handling we must perform
  121. detectOS
  122. # Locate the Karaf home directory
  123. locateHome
  124. # Locate the Karaf base directory
  125. locateBase
  126. # Locate the Karaf data directory
  127. locateData
  128. # Locate the Karaf etc directory
  129. locateEtc
  130. # Enable or not the Karaf output redirection
  131. enableRedirect
  132. }
  133. run() {
  134. if $cygwin; then
  135. KARAF_HOME=`cygpath --path --windows "$KARAF_HOME"`
  136. KARAF_BASE=`cygpath --path --windows "$KARAF_BASE"`
  137. KARAF_DATA=`cygpath --path --windows "$KARAF_DATA"`
  138. KARAF_ETC=`cygpath --path --windows "$KARAF_ETC"`
  139. if [ ! -z "$CLASSPATH" ]; then
  140. CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  141. fi
  142. fi
  143. # Ensure the log directory exists -- we need to have a place to redirect stdout/stderr
  144. if [ ! -d "$KARAF_DATA/log" ]; then
  145. mkdir -p "$KARAF_DATA/log"
  146. fi
  147. exec "$KARAF_HOME"/bin/karaf server "$@" >> "$KARAF_REDIRECT" 2>&1 &
  148. }
  149. main() {
  150. init
  151. run "$@"
  152. }
  153. main "$@"