domain.sh 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #!/bin/sh
  2. DIRNAME=`dirname "$0"`
  3. PROGNAME=`basename "$0"`
  4. GREP="grep"
  5. # Use the maximum available, or set MAX_FD != -1 to use that
  6. MAX_FD="maximum"
  7. # OS specific support (must be 'true' or 'false').
  8. cygwin=false;
  9. darwin=false;
  10. linux=false;
  11. case "`uname`" in
  12. CYGWIN*)
  13. cygwin=true
  14. ;;
  15. Darwin*)
  16. darwin=true
  17. ;;
  18. Linux)
  19. linux=true
  20. ;;
  21. esac
  22. # Read an optional running configuration file
  23. if [ "x$DOMAIN_CONF" = "x" ]; then
  24. DOMAIN_CONF="$DIRNAME/domain.conf"
  25. fi
  26. if [ -r "$DOMAIN_CONF" ]; then
  27. . "$DOMAIN_CONF"
  28. fi
  29. # For Cygwin, ensure paths are in UNIX format before anything is touched
  30. if $cygwin ; then
  31. [ -n "$JBOSS_HOME" ] &&
  32. JBOSS_HOME=`cygpath --unix "$JBOSS_HOME"`
  33. [ -n "$JAVA_HOME" ] &&
  34. JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  35. [ -n "$JAVAC_JAR" ] &&
  36. JAVAC_JAR=`cygpath --unix "$JAVAC_JAR"`
  37. fi
  38. # Setup JBOSS_HOME
  39. RESOLVED_JBOSS_HOME=`cd "$DIRNAME/.."; pwd`
  40. if [ "x$JBOSS_HOME" = "x" ]; then
  41. # get the full path (without any relative bits)
  42. JBOSS_HOME=$RESOLVED_JBOSS_HOME
  43. else
  44. SANITIZED_JBOSS_HOME=`cd "$JBOSS_HOME"; pwd`
  45. if [ "$RESOLVED_JBOSS_HOME" != "$SANITIZED_JBOSS_HOME" ]; then
  46. echo "WARNING JBOSS_HOME may be pointing to a different installation - unpredictable results may occur."
  47. echo ""
  48. fi
  49. fi
  50. export JBOSS_HOME
  51. # Setup the JVM
  52. if [ "x$JAVA" = "x" ]; then
  53. if [ "x$JAVA_HOME" != "x" ]; then
  54. JAVA="$JAVA_HOME/bin/java"
  55. else
  56. JAVA="java"
  57. fi
  58. fi
  59. # Check for -d32/-d64 in JAVA_OPTS
  60. JVM_OPTVERSION="-version"
  61. JVM_D64_OPTION=`echo $JAVA_OPTS | $GREP "\-d64"`
  62. JVM_D32_OPTION=`echo $JAVA_OPTS | $GREP "\-d32"`
  63. test "x$JVM_D64_OPTION" != "x" && JVM_OPTVERSION="-d64 $JVM_OPTVERSION"
  64. test "x$JVM_D32_OPTION" != "x" && JVM_OPTVERSION="-d32 $JVM_OPTVERSION"
  65. # If -server not set in JAVA_OPTS, set it, if supported
  66. SERVER_SET=`echo $JAVA_OPTS | $GREP "\-server"`
  67. if [ "x$SERVER_SET" = "x" ]; then
  68. # Check for SUN(tm) JVM w/ HotSpot support
  69. if [ "x$HAS_HOTSPOT" = "x" ]; then
  70. HAS_HOTSPOT=`"$JAVA" $JVM_OPTVERSION -version 2>&1 | $GREP -i HotSpot`
  71. fi
  72. # Check for OpenJDK JVM w/server support
  73. if [ "x$HAS_OPENJDK" = "x" ]; then
  74. HAS_OPENJDK=`"$JAVA" $JVM_OPTVERSION 2>&1 | $GREP -i OpenJDK`
  75. fi
  76. # Check for IBM JVM w/server support
  77. if [ "x$HAS_IBM" = "x" ]; then
  78. HAS_IBM=`"$JAVA" $JVM_OPTVERSION 2>&1 | $GREP -i "IBM J9"`
  79. fi
  80. # Enable -server if we have Hotspot or OpenJDK, unless we can't
  81. if [ "x$HAS_HOTSPOT" != "x" -o "x$HAS_OPENJDK" != "x" -o "x$HAS_IBM" != "x" ]; then
  82. # MacOS does not support -server flag
  83. if [ "$darwin" != "true" ]; then
  84. PROCESS_CONTROLLER_JAVA_OPTS="-server $PROCESS_CONTROLLER_JAVA_OPTS"
  85. HOST_CONTROLLER_JAVA_OPTS="-server $HOST_CONTROLLER_JAVA_OPTS"
  86. JVM_OPTVERSION="-server $JVM_OPTVERSION"
  87. fi
  88. fi
  89. else
  90. JVM_OPTVERSION="-server $JVM_OPTVERSION"
  91. fi
  92. if [ "x$JBOSS_MODULEPATH" = "x" ]; then
  93. JBOSS_MODULEPATH="$JBOSS_HOME/modules"
  94. fi
  95. if $linux; then
  96. # consolidate the host-controller and command line opts
  97. HOST_CONTROLLER_OPTS="$HOST_CONTROLLER_JAVA_OPTS $@"
  98. # process the host-controller options
  99. for var in $HOST_CONTROLLER_OPTS
  100. do
  101. case $var in
  102. -Djboss.domain.base.dir=*)
  103. JBOSS_BASE_DIR=`readlink -m ${var#*=}`
  104. ;;
  105. -Djboss.domain.log.dir=*)
  106. JBOSS_LOG_DIR=`readlink -m ${var#*=}`
  107. ;;
  108. -Djboss.domain.config.dir=*)
  109. JBOSS_CONFIG_DIR=`readlink -m ${var#*=}`
  110. ;;
  111. esac
  112. done
  113. fi
  114. # determine the default base dir, if not set
  115. if [ "x$JBOSS_BASE_DIR" = "x" ]; then
  116. JBOSS_BASE_DIR="$JBOSS_HOME/domain"
  117. fi
  118. # determine the default log dir, if not set
  119. if [ "x$JBOSS_LOG_DIR" = "x" ]; then
  120. JBOSS_LOG_DIR="$JBOSS_BASE_DIR/log"
  121. fi
  122. # determine the default configuration dir, if not set
  123. if [ "x$JBOSS_CONFIG_DIR" = "x" ]; then
  124. JBOSS_CONFIG_DIR="$JBOSS_BASE_DIR/configuration"
  125. fi
  126. # Setup the java path to invoke from JVM
  127. # Needed to start domain from cygwin when the JAVA path will result in an invalid path
  128. JAVA_FROM_JVM="$JAVA"
  129. # For Cygwin, switch paths to Windows format before running java
  130. if $cygwin; then
  131. JBOSS_HOME=`cygpath --path --windows "$JBOSS_HOME"`
  132. JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  133. JAVA_FROM_JVM=`cygpath --path --absolute --windows "$JAVA_FROM_JVM"`
  134. JBOSS_BASE_DIR=`cygpath --path --windows "$JBOSS_BASE_DIR"`
  135. JBOSS_LOG_DIR=`cygpath --path --windows "$JBOSS_LOG_DIR"`
  136. JBOSS_CONFIG_DIR=`cygpath --path --windows "$JBOSS_CONFIG_DIR"`
  137. JBOSS_MODULEPATH=`cygpath --path --windows "$JBOSS_MODULEPATH"`
  138. fi
  139. # Display our environment
  140. echo "========================================================================="
  141. echo ""
  142. echo " JBoss Bootstrap Environment"
  143. echo ""
  144. echo " JBOSS_HOME: $JBOSS_HOME"
  145. echo ""
  146. echo " JAVA: $JAVA"
  147. echo ""
  148. echo " JAVA_OPTS: $JAVA_OPTS"
  149. echo ""
  150. echo "========================================================================="
  151. echo ""
  152. while true; do
  153. if [ "x$LAUNCH_JBOSS_IN_BACKGROUND" = "x" ]; then
  154. # Execute the JVM in the foreground
  155. eval \"$JAVA\" -D\"[Process Controller]\" $PROCESS_CONTROLLER_JAVA_OPTS \
  156. \"-Dorg.jboss.boot.log.file=$JBOSS_LOG_DIR/process-controller.log\" \
  157. \"-Dlogging.configuration=file:$JBOSS_CONFIG_DIR/logging.properties\" \
  158. -jar \"$JBOSS_HOME/jboss-modules.jar\" \
  159. -mp \"${JBOSS_MODULEPATH}\" \
  160. org.jboss.as.process-controller \
  161. -jboss-home \"$JBOSS_HOME\" \
  162. -jvm \"$JAVA_FROM_JVM\" \
  163. -mp \"${JBOSS_MODULEPATH}\" \
  164. -- \
  165. \"-Dorg.jboss.boot.log.file=$JBOSS_LOG_DIR/host-controller.log\" \
  166. \"-Dlogging.configuration=file:$JBOSS_CONFIG_DIR/logging.properties\" \
  167. $HOST_CONTROLLER_JAVA_OPTS \
  168. -- \
  169. -default-jvm \"$JAVA_FROM_JVM\" \
  170. '"$@"'
  171. JBOSS_STATUS=$?
  172. else
  173. # Execute the JVM in the background
  174. eval \"$JAVA\" -D\"[Process Controller]\" $PROCESS_CONTROLLER_JAVA_OPTS \
  175. \"-Dorg.jboss.boot.log.file=$JBOSS_LOG_DIR/process-controller.log\" \
  176. \"-Dlogging.configuration=file:$JBOSS_CONFIG_DIR/logging.properties\" \
  177. -jar \"$JBOSS_HOME/jboss-modules.jar\" \
  178. -mp \"${JBOSS_MODULEPATH}\" \
  179. org.jboss.as.process-controller \
  180. -jboss-home \"$JBOSS_HOME\" \
  181. -jvm \"$JAVA_FROM_JVM\" \
  182. -mp \"${JBOSS_MODULEPATH}\" \
  183. -- \
  184. \"-Dorg.jboss.boot.log.file=$JBOSS_LOG_DIR/host-controller.log\" \
  185. \"-Dlogging.configuration=file:$JBOSS_CONFIG_DIR/logging.properties\" \
  186. $HOST_CONTROLLER_JAVA_OPTS \
  187. -- \
  188. -default-jvm \"$JAVA_FROM_JVM\" \
  189. '"$@"' "&"
  190. JBOSS_PID=$!
  191. # Trap common signals and relay them to the jboss process
  192. trap "kill -HUP $JBOSS_PID" HUP
  193. trap "kill -TERM $JBOSS_PID" INT
  194. trap "kill -QUIT $JBOSS_PID" QUIT
  195. trap "kill -PIPE $JBOSS_PID" PIPE
  196. trap "kill -TERM $JBOSS_PID" TERM
  197. if [ "x$JBOSS_PIDFILE" != "x" ]; then
  198. echo $JBOSS_PID > $JBOSS_PIDFILE
  199. fi
  200. # Wait until the background process exits
  201. WAIT_STATUS=128
  202. while [ "$WAIT_STATUS" -ge 128 ]; do
  203. wait $JBOSS_PID 2>/dev/null
  204. WAIT_STATUS=$?
  205. if [ "$WAIT_STATUS" -gt 128 ]; then
  206. SIGNAL=`expr $WAIT_STATUS - 128`
  207. SIGNAL_NAME=`kill -l $SIGNAL`
  208. echo "*** JBossAS process ($JBOSS_PID) received $SIGNAL_NAME signal ***" >&2
  209. fi
  210. done
  211. if [ "$WAIT_STATUS" -lt 127 ]; then
  212. JBOSS_STATUS=$WAIT_STATUS
  213. else
  214. JBOSS_STATUS=0
  215. fi
  216. if [ "$JBOSS_STATUS" -ne 10 ]; then
  217. # Wait for a complete shudown
  218. wait $JBOSS_PID 2>/dev/null
  219. fi
  220. if [ "x$JBOSS_PIDFILE" != "x" ]; then
  221. grep "$JBOSS_PID" $JBOSS_PIDFILE && rm $JBOSS_PIDFILE
  222. fi
  223. fi
  224. if [ "$JBOSS_STATUS" -eq 10 ]; then
  225. echo "Restarting JBoss..."
  226. else
  227. exit $JBOSS_STATUS
  228. fi
  229. done