standalone.sh 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. #!/bin/sh
  2. # Use --debug to activate debug mode with an optional argument to specify the port.
  3. # Usage : standalone.bat --debug
  4. # standalone.bat --debug 9797
  5. if [ ! -z "$DOCKER_START_DELAY" ] ; then
  6. echo SLEEP DELAY $DOCKER_START_DELAY
  7. sleep $DOCKER_START_DELAY
  8. fi
  9. if [ -f /opt/jboss/start.log ] ; then
  10. echo ###### start.log #########
  11. cat /opt/jboss/start.log
  12. echo ##########################
  13. echo .
  14. echo .
  15. fi
  16. ./hlic template /opt/jboss/jboss-as-7.2.0.Final/standalone/configuration/standalone.xml.template /opt/jboss/jboss-as-7.2.0.Final/standalone/configuration/standalone.xml
  17. if [ ! $? -eq 0 ] ; then
  18. echo FAILED
  19. exit 1
  20. fi
  21. if [ ! -z "$DEV_MODE" ] ; then
  22. echo ###### standalone.xml ######
  23. cat /opt/jboss/jboss-as-7.2.0.Final/standalone/configuration/standalone.xml
  24. echo ############################
  25. echo .
  26. echo .
  27. fi
  28. # By default debug mode is disable.
  29. DEBUG_MODE=false
  30. DEBUG_PORT="8787"
  31. SERVER_OPTS=""
  32. while [ "$#" -gt 0 ]
  33. do
  34. case "$1" in
  35. --debug)
  36. DEBUG_MODE=true
  37. shift
  38. if [ -n "$1" ] && [ "${1#*-}" = "$1" ]; then
  39. DEBUG_PORT=$1
  40. else
  41. SERVER_OPTS="$SERVER_OPTS $1"
  42. fi
  43. ;;
  44. --)
  45. shift
  46. break;;
  47. *)
  48. SERVER_OPTS="$SERVER_OPTS \"$1\""
  49. ;;
  50. esac
  51. shift
  52. done
  53. DIRNAME=`dirname "$0"`
  54. PROGNAME=`basename "$0"`
  55. GREP="grep"
  56. # Use the maximum available, or set MAX_FD != -1 to use that
  57. MAX_FD="maximum"
  58. # OS specific support (must be 'true' or 'false').
  59. cygwin=false;
  60. darwin=false;
  61. linux=false;
  62. case "`uname`" in
  63. CYGWIN*)
  64. cygwin=true
  65. ;;
  66. Darwin*)
  67. darwin=true
  68. ;;
  69. Linux)
  70. linux=true
  71. ;;
  72. esac
  73. # For Cygwin, ensure paths are in UNIX format before anything is touched
  74. if $cygwin ; then
  75. [ -n "$JBOSS_HOME" ] &&
  76. JBOSS_HOME=`cygpath --unix "$JBOSS_HOME"`
  77. [ -n "$JAVA_HOME" ] &&
  78. JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  79. [ -n "$JAVAC_JAR" ] &&
  80. JAVAC_JAR=`cygpath --unix "$JAVAC_JAR"`
  81. fi
  82. # Setup JBOSS_HOME
  83. RESOLVED_JBOSS_HOME=`cd "$DIRNAME/.."; pwd`
  84. if [ "x$JBOSS_HOME" = "x" ]; then
  85. # get the full path (without any relative bits)
  86. JBOSS_HOME=$RESOLVED_JBOSS_HOME
  87. else
  88. SANITIZED_JBOSS_HOME=`cd "$JBOSS_HOME"; pwd`
  89. if [ "$RESOLVED_JBOSS_HOME" != "$SANITIZED_JBOSS_HOME" ]; then
  90. echo ""
  91. echo " WARNING: JBOSS_HOME may be pointing to a different installation - unpredictable results may occur."
  92. echo ""
  93. echo " JBOSS_HOME: $JBOSS_HOME"
  94. echo ""
  95. sleep 2s
  96. fi
  97. fi
  98. export JBOSS_HOME
  99. # Read an optional running configuration file
  100. if [ "x$RUN_CONF" = "x" ]; then
  101. RUN_CONF="$DIRNAME/standalone.conf"
  102. fi
  103. if [ -r "$RUN_CONF" ]; then
  104. . "$RUN_CONF"
  105. fi
  106. # Set debug settings if not already set
  107. if [ "$DEBUG_MODE" = "true" ]; then
  108. DEBUG_OPT=`echo $JAVA_OPTS | $GREP "\-agentlib:jdwp"`
  109. if [ "x$DEBUG_OPT" = "x" ]; then
  110. JAVA_OPTS="$JAVA_OPTS -agentlib:jdwp=transport=dt_socket,address=$DEBUG_PORT,server=y,suspend=n"
  111. else
  112. echo "Debug already enabled in JAVA_OPTS, ignoring --debug argument"
  113. fi
  114. fi
  115. # Setup the JVM
  116. if [ "x$JAVA" = "x" ]; then
  117. if [ "x$JAVA_HOME" != "x" ]; then
  118. JAVA="$JAVA_HOME/bin/java"
  119. else
  120. JAVA="java"
  121. fi
  122. fi
  123. if [ "$PRESERVE_JAVA_OPTS" != "true" ]; then
  124. # Check for -d32/-d64 in JAVA_OPTS
  125. JVM_D64_OPTION=`echo $JAVA_OPTS | $GREP "\-d64"`
  126. JVM_D32_OPTION=`echo $JAVA_OPTS | $GREP "\-d32"`
  127. # Check If server or client is specified
  128. SERVER_SET=`echo $JAVA_OPTS | $GREP "\-server"`
  129. CLIENT_SET=`echo $JAVA_OPTS | $GREP "\-client"`
  130. if [ "x$JVM_D32_OPTION" != "x" ]; then
  131. JVM_OPTVERSION="-d32"
  132. elif [ "x$JVM_D64_OPTION" != "x" ]; then
  133. JVM_OPTVERSION="-d64"
  134. elif $darwin && [ "x$SERVER_SET" = "x" ]; then
  135. # Use 32-bit on Mac, unless server has been specified or the user opts are incompatible
  136. "$JAVA" -d32 $JAVA_OPTS -version > /dev/null 2>&1 && PREPEND_JAVA_OPTS="-d32" && JVM_OPTVERSION="-d32"
  137. fi
  138. CLIENT_VM=false
  139. if [ "x$CLIENT_SET" != "x" ]; then
  140. CLIENT_VM=true
  141. elif [ "x$SERVER_SET" = "x" ]; then
  142. if $darwin && [ "$JVM_OPTVERSION" = "-d32" ]; then
  143. # Prefer client for Macs, since they are primarily used for development
  144. CLIENT_VM=true
  145. PREPEND_JAVA_OPTS="$PREPEND_JAVA_OPTS -client"
  146. else
  147. PREPEND_JAVA_OPTS="$PREPEND_JAVA_OPTS -server"
  148. fi
  149. fi
  150. if [ $CLIENT_VM = false ]; then
  151. NO_COMPRESSED_OOPS=`echo $JAVA_OPTS | $GREP "\-XX:\-UseCompressedOops"`
  152. if [ "x$NO_COMPRESSED_OOPS" = "x" ]; then
  153. "$JAVA" $JVM_OPTVERSION -server -XX:+UseCompressedOops -version >/dev/null 2>&1 && PREPEND_JAVA_OPTS="$PREPEND_JAVA_OPTS -XX:+UseCompressedOops"
  154. fi
  155. fi
  156. JAVA_OPTS="$PREPEND_JAVA_OPTS $JAVA_OPTS"
  157. fi
  158. if [ "x$JBOSS_MODULEPATH" = "x" ]; then
  159. JBOSS_MODULEPATH="$JBOSS_HOME/modules"
  160. fi
  161. if $linux; then
  162. # consolidate the server and command line opts
  163. CONSOLIDATED_OPTS="$JAVA_OPTS $SERVER_OPTS"
  164. # process the standalone options
  165. for var in $CONSOLIDATED_OPTS
  166. do
  167. case $var in
  168. -Djboss.server.base.dir=*)
  169. JBOSS_BASE_DIR=`readlink -m ${var#*=}`
  170. ;;
  171. -Djboss.server.log.dir=*)
  172. JBOSS_LOG_DIR=`readlink -m ${var#*=}`
  173. ;;
  174. -Djboss.server.config.dir=*)
  175. JBOSS_CONFIG_DIR=`readlink -m ${var#*=}`
  176. ;;
  177. esac
  178. done
  179. fi
  180. # determine the default base dir, if not set
  181. if [ "x$JBOSS_BASE_DIR" = "x" ]; then
  182. JBOSS_BASE_DIR="$JBOSS_HOME/standalone"
  183. fi
  184. # determine the default log dir, if not set
  185. if [ "x$JBOSS_LOG_DIR" = "x" ]; then
  186. JBOSS_LOG_DIR="$JBOSS_BASE_DIR/log"
  187. fi
  188. # determine the default configuration dir, if not set
  189. if [ "x$JBOSS_CONFIG_DIR" = "x" ]; then
  190. JBOSS_CONFIG_DIR="$JBOSS_BASE_DIR/configuration"
  191. fi
  192. # For Cygwin, switch paths to Windows format before running java
  193. if $cygwin; then
  194. JBOSS_HOME=`cygpath --path --windows "$JBOSS_HOME"`
  195. JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  196. JBOSS_MODULEPATH=`cygpath --path --windows "$JBOSS_MODULEPATH"`
  197. JBOSS_BASE_DIR=`cygpath --path --windows "$JBOSS_BASE_DIR"`
  198. JBOSS_LOG_DIR=`cygpath --path --windows "$JBOSS_LOG_DIR"`
  199. JBOSS_CONFIG_DIR=`cygpath --path --windows "$JBOSS_CONFIG_DIR"`
  200. fi
  201. # Display our environment
  202. echo "========================================================================="
  203. echo ""
  204. echo " JBoss Bootstrap Environment"
  205. echo ""
  206. echo " JBOSS_HOME: $JBOSS_HOME"
  207. echo ""
  208. echo " JAVA: $JAVA"
  209. echo ""
  210. echo " JAVA_OPTS: $JAVA_OPTS"
  211. echo ""
  212. echo "========================================================================="
  213. echo ""
  214. while true; do
  215. if [ "x$LAUNCH_JBOSS_IN_BACKGROUND" = "x" ]; then
  216. # Execute the JVM in the foreground
  217. eval \"$JAVA\" -D\"[Standalone]\" $JAVA_OPTS \
  218. \"-Dorg.jboss.boot.log.file=$JBOSS_LOG_DIR/server.log\" \
  219. \"-Dlogging.configuration=file:$JBOSS_CONFIG_DIR/logging.properties\" \
  220. -jar \"$JBOSS_HOME/jboss-modules.jar\" \
  221. -mp \"${JBOSS_MODULEPATH}\" \
  222. -jaxpmodule "javax.xml.jaxp-provider" \
  223. org.jboss.as.standalone \
  224. -Djboss.home.dir=\"$JBOSS_HOME\" \
  225. -Djboss.server.base.dir=\"$JBOSS_BASE_DIR\" \
  226. "$SERVER_OPTS"
  227. JBOSS_STATUS=$?
  228. else
  229. # Execute the JVM in the background
  230. eval \"$JAVA\" -D\"[Standalone]\" $JAVA_OPTS \
  231. \"-Dorg.jboss.boot.log.file=$JBOSS_LOG_DIR/server.log\" \
  232. \"-Dlogging.configuration=file:$JBOSS_CONFIG_DIR/logging.properties\" \
  233. -jar \"$JBOSS_HOME/jboss-modules.jar\" \
  234. -mp \"${JBOSS_MODULEPATH}\" \
  235. -jaxpmodule "javax.xml.jaxp-provider" \
  236. org.jboss.as.standalone \
  237. -Djboss.home.dir=\"$JBOSS_HOME\" \
  238. -Djboss.server.base.dir=\"$JBOSS_BASE_DIR\" \
  239. "$SERVER_OPTS" "&"
  240. JBOSS_PID=$!
  241. # Trap common signals and relay them to the jboss process
  242. trap "kill -HUP $JBOSS_PID" HUP
  243. trap "kill -TERM $JBOSS_PID" INT
  244. trap "kill -QUIT $JBOSS_PID" QUIT
  245. trap "kill -PIPE $JBOSS_PID" PIPE
  246. trap "kill -TERM $JBOSS_PID" TERM
  247. if [ "x$JBOSS_PIDFILE" != "x" ]; then
  248. echo $JBOSS_PID > $JBOSS_PIDFILE
  249. fi
  250. # Wait until the background process exits
  251. WAIT_STATUS=128
  252. while [ "$WAIT_STATUS" -ge 128 ]; do
  253. wait $JBOSS_PID 2>/dev/null
  254. WAIT_STATUS=$?
  255. if [ "$WAIT_STATUS" -gt 128 ]; then
  256. SIGNAL=`expr $WAIT_STATUS - 128`
  257. SIGNAL_NAME=`kill -l $SIGNAL`
  258. echo "*** JBossAS process ($JBOSS_PID) received $SIGNAL_NAME signal ***" >&2
  259. fi
  260. done
  261. if [ "$WAIT_STATUS" -lt 127 ]; then
  262. JBOSS_STATUS=$WAIT_STATUS
  263. else
  264. JBOSS_STATUS=0
  265. fi
  266. if [ "$JBOSS_STATUS" -ne 10 ]; then
  267. # Wait for a complete shudown
  268. wait $JBOSS_PID 2>/dev/null
  269. fi
  270. if [ "x$JBOSS_PIDFILE" != "x" ]; then
  271. grep "$JBOSS_PID" $JBOSS_PIDFILE && rm $JBOSS_PIDFILE
  272. fi
  273. fi
  274. if [ "$JBOSS_STATUS" -eq 10 ]; then
  275. echo "Restarting JBoss..."
  276. else
  277. exit $JBOSS_STATUS
  278. fi
  279. done