standalone.sh 8.7 KB

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