|
| 1 | +############################################################################## |
| 2 | +## ## |
| 3 | +## Grails JVM Bootstrap for UN*X ## |
| 4 | +## ## |
| 5 | +############################################################################## |
| 6 | + |
| 7 | +PROGNAME=`basename "$0"` |
| 8 | +DIRNAME=`dirname "$0"` |
| 9 | + |
| 10 | +# Use the maximum available, or set MAX_FD != -1 to use that |
| 11 | +MAX_FD="maximum" |
| 12 | + |
| 13 | +warn() { |
| 14 | + echo "${PROGNAME}: $*" |
| 15 | +} |
| 16 | + |
| 17 | +die() { |
| 18 | + warn "$*" |
| 19 | + exit 1 |
| 20 | +} |
| 21 | + |
| 22 | +earlyInit() { |
| 23 | + return |
| 24 | +} |
| 25 | +lateInit() { |
| 26 | + return |
| 27 | +} |
| 28 | + |
| 29 | +GROOVY_STARTUP=~/.groovy/startup |
| 30 | +if [ -r "$GROOVY_STARTUP" ]; then |
| 31 | + . "$GROOVY_STARTUP" |
| 32 | +fi |
| 33 | + |
| 34 | +earlyInit |
| 35 | + |
| 36 | +# OS specific support (must be 'true' or 'false'). |
| 37 | +cygwin=false; |
| 38 | +darwin=false; |
| 39 | +case "`uname`" in |
| 40 | + CYGWIN*) |
| 41 | + cygwin=true |
| 42 | + ;; |
| 43 | + |
| 44 | + Darwin*) |
| 45 | + darwin=true |
| 46 | + ;; |
| 47 | +esac |
| 48 | + |
| 49 | +# Attempt to set JAVA_HOME if it's not already set |
| 50 | +if [ -z "$JAVA_HOME" ]; then |
| 51 | + |
| 52 | + # Set JAVA_HOME for Darwin |
| 53 | + if $darwin; then |
| 54 | + |
| 55 | + [ -z "$JAVA_HOME" -a -d "/Library/Java/Home" ] && |
| 56 | + export JAVA_HOME="/Library/Java/Home" |
| 57 | + |
| 58 | + [ -z "$JAVA_HOME" -a -d "/System/Library/Frameworks/JavaVM.framework/Home" ] && |
| 59 | + export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home" |
| 60 | + |
| 61 | + fi |
| 62 | + |
| 63 | +fi |
| 64 | + |
| 65 | +# For Cygwin, ensure paths are in UNIX format before anything is touched |
| 66 | +if $cygwin ; then |
| 67 | + [ -n "$GRAILS_HOME" ] && |
| 68 | + GRAILS_HOME=`cygpath --unix "$GRAILS_HOME"` |
| 69 | + [ -n "$JAVACMD" ] && |
| 70 | + JAVACMD=`cygpath --unix "$JAVACMD"` |
| 71 | + [ -n "$JAVA_HOME" ] && |
| 72 | + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` |
| 73 | + [ -n "$CP" ] && |
| 74 | + CP=`cygpath --path --unix "$CP"` |
| 75 | +fi |
| 76 | + |
| 77 | +# Remove possible trailing slash (after possible cygwin correction) |
| 78 | +GRAILS_HOME=`echo $GRAILS_HOME | sed -e 's|/$||g'` |
| 79 | + |
| 80 | +# Locate GRAILS_HOME if not it is not set |
| 81 | +if [ -z "$GRAILS_HOME" -o ! -d "$GRAILS_HOME" ] ; then |
| 82 | + # resolve links - $0 may be a link to groovy's home |
| 83 | + PRG="$0" |
| 84 | + |
| 85 | + # need this for relative symlinks |
| 86 | + while [ -h "$PRG" ] ; do |
| 87 | + ls=`ls -ld "$PRG"` |
| 88 | + link=`expr "$ls" : '.*-> \(.*\)$'` |
| 89 | + if expr "$link" : '/.*' > /dev/null; then |
| 90 | + PRG="$link" |
| 91 | + else |
| 92 | + PRG=`dirname "$PRG"`"/$link" |
| 93 | + fi |
| 94 | + done |
| 95 | + |
| 96 | + SAVED="`pwd`" |
| 97 | + cd "`dirname \"$PRG\"`/.." |
| 98 | + GRAILS_HOME="`pwd -P`" |
| 99 | + cd "$SAVED" |
| 100 | +fi |
| 101 | + |
| 102 | +# Warn the user if JAVA_HOME and/or GRAILS_HOME are not set. |
| 103 | +if [ -z "$JAVA_HOME" ] ; then |
| 104 | + die "JAVA_HOME environment variable is not set" |
| 105 | +elif [ ! -d "$JAVA_HOME" ] ; then |
| 106 | + die "JAVA_HOME is not a directory: $JAVA_HOME" |
| 107 | +fi |
| 108 | + |
| 109 | +if [ -z "$GRAILS_HOME" ] ; then |
| 110 | + warn "GRAILS_HOME environment variable is not set" |
| 111 | +fi |
| 112 | + |
| 113 | +if [ ! -d "$GRAILS_HOME" ] ; then |
| 114 | + die "GRAILS_HOME is not a directory: $GRAILS_HOME" |
| 115 | +fi |
| 116 | + |
| 117 | +# Use default groovy-conf config |
| 118 | +if [ -z "$STARTER_CONF" ]; then |
| 119 | + STARTER_CONF="$GRAILS_HOME/conf/groovy-starter.conf" |
| 120 | +fi |
| 121 | +STARTER_CLASSPATH="wrapper/grails-wrapper-runtime-2.2.1.jar:wrapper:." |
| 122 | + |
| 123 | +# Allow access to Cocoa classes on OS X |
| 124 | +if $darwin; then |
| 125 | + STARTER_CLASSPATH="$STARTER_CLASSPATH:/System/Library/Java/Support" |
| 126 | +fi |
| 127 | + |
| 128 | +# Create the final classpath |
| 129 | +# Setting a classpath using the -cp or -classpath option means not to use |
| 130 | +# the global classpath. Groovy behaves then the same as the java |
| 131 | +# interpreter |
| 132 | +if [ -n "$CP" ] ; then |
| 133 | + CP="$CP" |
| 134 | +elif [ -n "$CLASSPATH" ] ; then |
| 135 | + CP="$CLASSPATH" |
| 136 | +fi |
| 137 | + |
| 138 | +# Determine the Java command to use to start the JVM |
| 139 | +if [ -z "$JAVACMD" ]; then |
| 140 | + if [ -n "$JAVA_HOME" ]; then |
| 141 | + if [ -x "$JAVA_HOME/jre/sh/java" ]; then |
| 142 | + # IBM's JDK on AIX uses strange locations for the executables |
| 143 | + JAVACMD="$JAVA_HOME/jre/sh/java" |
| 144 | + else |
| 145 | + JAVACMD="$JAVA_HOME/bin/java" |
| 146 | + fi |
| 147 | + else |
| 148 | + JAVACMD="java" |
| 149 | + fi |
| 150 | +fi |
| 151 | +if [ ! -x "$JAVACMD" ]; then |
| 152 | + die "JAVA_HOME is not defined correctly; can not execute: $JAVACMD" |
| 153 | +fi |
| 154 | + |
| 155 | +# Increase the maximum file descriptors if we can |
| 156 | +if [ "$cygwin" = "false" ]; then |
| 157 | + MAX_FD_LIMIT=`ulimit -H -n` |
| 158 | + if [ "$MAX_FD_LIMIT" != "unlimited" ]; then |
| 159 | + if [ $? -eq 0 ]; then |
| 160 | + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ]; then |
| 161 | + # use the businessSystem max |
| 162 | + MAX_FD="$MAX_FD_LIMIT" |
| 163 | + fi |
| 164 | + |
| 165 | + ulimit -n $MAX_FD |
| 166 | + if [ $? -ne 0 ]; then |
| 167 | + warn "Could not set maximum file descriptor limit: $MAX_FD" |
| 168 | + fi |
| 169 | + else |
| 170 | + warn "Could not query businessSystem maximum file descriptor limit: $MAX_FD_LIMIT" |
| 171 | + fi |
| 172 | + fi |
| 173 | +fi |
| 174 | + |
| 175 | +# Fix the cygwin agent issue |
| 176 | +AGENT_GRAILS_HOME=$GRAILS_HOME |
| 177 | +if $cygwin ; then |
| 178 | + [ -n "$GRAILS_HOME" ] && |
| 179 | + AGENT_GRAILS_HOME=`cygpath --windows "$GRAILS_HOME"` |
| 180 | +fi |
| 181 | + |
| 182 | +if [ -z "$GRAILS_AGENT_CACHE_DIR" ]; then |
| 183 | + GRAILS_AGENT_CACHE_DIR=~/.grails/2.2.1/ |
| 184 | +fi |
| 185 | +SPRINGLOADED_PARAMS=profile=grails;cacheDir=$GRAILS_AGENT_CACHE_DIR |
| 186 | +if [ ! -d "$GRAILS_AGENT_CACHE_DIR" ]; then |
| 187 | + mkdir -p "$GRAILS_AGENT_CACHE_DIR" |
| 188 | +fi |
| 189 | + |
| 190 | +# Process JVM args |
| 191 | +AGENT_STRING="-javaagent:wrapper/springloaded-core-1.1.1.jar -noverify -Dspringloaded=\"$SPRINGLOADED_PARAMS\"" |
| 192 | +CMD_LINE_ARGS="" |
| 193 | +DISABLE_RELOADING=false |
| 194 | + |
| 195 | +while true; do |
| 196 | + if [ "$1" = "-cp" ] || [ "$1" = "-classpath" ]; then |
| 197 | + CP=$2 |
| 198 | + shift 2 |
| 199 | + break |
| 200 | + fi |
| 201 | + |
| 202 | + if [ "$1" = "-reloading" ]; then |
| 203 | + AGENT=$AGENT_STRING |
| 204 | + shift |
| 205 | + break |
| 206 | + fi |
| 207 | + |
| 208 | + if [ "$1" = "-noreloading" ]; then |
| 209 | + DISABLE_RELOADING=true |
| 210 | + shift |
| 211 | + break |
| 212 | + fi |
| 213 | + |
| 214 | + if [ "$1" = "-debug" ]; then |
| 215 | + JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Dgrails.full.stacktrace=true -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005" |
| 216 | + shift |
| 217 | + break |
| 218 | + fi |
| 219 | + |
| 220 | + if [ "$1" != -* ]; then |
| 221 | + break |
| 222 | + fi |
| 223 | + |
| 224 | + CMD_LINE_ARGS="$CMD_LINE_ARGS $1" |
| 225 | + shift |
| 226 | +done |
| 227 | + |
| 228 | +# Enable agent-based reloading for the 'run-app' command. |
| 229 | +if ! $DISABLE_RELOADING; then |
| 230 | + for a in "$@"; do |
| 231 | + if [ "$a" = "run-app" ]; then |
| 232 | + AGENT=$AGENT_STRING |
| 233 | + fi |
| 234 | + done |
| 235 | + |
| 236 | + if [ $# = 0 ]; then |
| 237 | + AGENT=$AGENT_STRING |
| 238 | + fi |
| 239 | +fi |
| 240 | + |
| 241 | +ARGUMENTS="$CMD_LINE_ARGS $@" |
| 242 | + |
| 243 | +# Setup Profiler |
| 244 | +useprofiler=false |
| 245 | +if [ "x$PROFILER" != "x" ]; then |
| 246 | + if [ -r "$PROFILER" ]; then |
| 247 | + . $PROFILER |
| 248 | + useprofiler=true |
| 249 | + else |
| 250 | + die "Profiler file not found: $PROFILER" |
| 251 | + fi |
| 252 | +fi |
| 253 | + |
| 254 | +# For Darwin, use classes.jar for TOOLS_JAR |
| 255 | +TOOLS_JAR="$JAVA_HOME/lib/tools.jar" |
| 256 | +if $darwin; then |
| 257 | + JAVA_OPTS="-Xdock:name=Grails -Xdock:icon=$GRAILS_HOME/media/icons/grails.icns $JAVA_OPTS" |
| 258 | +# TOOLS_JAR="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Classes/classes.jar" |
| 259 | +fi |
| 260 | + |
| 261 | +# For Cygwin, switch paths to Windows format before running java |
| 262 | +if $cygwin; then |
| 263 | + GRAILS_HOME=`cygpath --path --mixed "$GRAILS_HOME"` |
| 264 | + JAVA_HOME=`cygpath --path --mixed "$JAVA_HOME"` |
| 265 | + STARTER_CONF=`cygpath --path --mixed "$STARTER_CONF"` |
| 266 | + CP=`cygpath --path --mixed "$CP"` |
| 267 | + TOOLS_JAR=`cygpath --path --mixed "$TOOLS_JAR"` |
| 268 | + STARTER_CLASSPATH=`cygpath --path --mixed "$STARTER_CLASSPATH"` |
| 269 | + # We build the pattern for arguments to be converted via cygpath |
| 270 | + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` |
| 271 | + SEP="" |
| 272 | + for dir in $ROOTDIRSRAW; do |
| 273 | + ROOTDIRS="$ROOTDIRS$SEP$dir" |
| 274 | + SEP="|" |
| 275 | + done |
| 276 | + OURCYGPATTERN="(^($ROOTDIRS))" |
| 277 | + # Add a user-defined pattern to the cygpath arguments |
| 278 | + if [ "$GROOVY_CYGPATTERN" != "" ] ; then |
| 279 | + OURCYGPATTERN="$OURCYGPATTERN|($GROOVY_CYGPATTERN)" |
| 280 | + fi |
| 281 | + # Now convert the arguments |
| 282 | + ARGUMENTS="" |
| 283 | + for arg in "$@" ; do |
| 284 | + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` |
| 285 | + if [ $CHECK -ne 0 ] ; then |
| 286 | + convArg=`cygpath --path --ignore --mixed "$arg"` |
| 287 | + else |
| 288 | + convArg=$arg |
| 289 | + fi |
| 290 | + ARGUMENTS="$ARGUMENTS $convArg" |
| 291 | + done |
| 292 | +fi |
| 293 | + |
| 294 | +STARTER_MAIN_CLASS=org.grails.wrapper.GrailsWrapper |
| 295 | + |
| 296 | +lateInit |
| 297 | + |
| 298 | +startGrails() { |
| 299 | + CLASS=$1 |
| 300 | + shift |
| 301 | + if [ -n "$GRAILS_OPTS" ] |
| 302 | + then |
| 303 | + GRAILS_OPTS="$GRAILS_OPTS" |
| 304 | + else |
| 305 | + GRAILS_OPTS="-server -Xmx768M -Xms64M -XX:PermSize=32m -XX:MaxPermSize=256m -Dfile.encoding=UTF-8" |
| 306 | + fi |
| 307 | + JAVA_OPTS="$GRAILS_OPTS $JAVA_OPTS $AGENT" |
| 308 | + # Start the Profiler or the JVM |
| 309 | + if $useprofiler; then |
| 310 | + runProfiler |
| 311 | + else |
| 312 | + if [ $# -eq 0 ] ; then # no argument given |
| 313 | + exec "$JAVACMD" $JAVA_OPTS \ |
| 314 | + -classpath "$STARTER_CLASSPATH" \ |
| 315 | + -Dgrails.home="$GRAILS_HOME" \ |
| 316 | + -Dtools.jar="$TOOLS_JAR" \ |
| 317 | + $STARTER_MAIN_CLASS \ |
| 318 | + --main $CLASS \ |
| 319 | + --conf "$STARTER_CONF" \ |
| 320 | + --classpath "$CP" |
| 321 | + else |
| 322 | + exec "$JAVACMD" $JAVA_OPTS \ |
| 323 | + -classpath "$STARTER_CLASSPATH" \ |
| 324 | + -Dgrails.home="$GRAILS_HOME" \ |
| 325 | + -Dtools.jar="$TOOLS_JAR" \ |
| 326 | + $STARTER_MAIN_CLASS \ |
| 327 | + --main $CLASS \ |
| 328 | + --conf "$STARTER_CONF" \ |
| 329 | + --classpath "$CP" \ |
| 330 | + "${ARGUMENTS}" |
| 331 | + fi |
| 332 | + fi |
| 333 | +} |
| 334 | + |
| 335 | +startGrails $STARTER_MAIN_CLASS "$@" |
0 commit comments