|
| 1 | +#!/usr/bin/env sh |
| 2 | + |
| 3 | +# |
| 4 | +# Copyright 2015 the original author or authors. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# https://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 | + |
| 19 | +############################################################################## |
| 20 | +## |
| 21 | +## ${applicationName} start up script for UN*X |
| 22 | +## |
| 23 | +############################################################################## |
| 24 | + |
| 25 | +# Attempt to set APP_HOME |
| 26 | +# Resolve links: \$0 may be a link |
| 27 | +PRG="\$0" |
| 28 | +# Need this for relative symlinks. |
| 29 | +while [ -h "\$PRG" ] ; do |
| 30 | + ls=`ls -ld "\$PRG"` |
| 31 | + link=`expr "\$ls" : '.*-> \\(.*\\)\$'` |
| 32 | + if expr "\$link" : '/.*' > /dev/null; then |
| 33 | + PRG="\$link" |
| 34 | + else |
| 35 | + PRG=`dirname "\$PRG"`"/\$link" |
| 36 | + fi |
| 37 | +done |
| 38 | +SAVED="`pwd`" |
| 39 | +cd "`dirname \"\$PRG\"`/${appHomeRelativePath}" >/dev/null |
| 40 | +APP_HOME="`pwd -P`" |
| 41 | +cd "\$SAVED" >/dev/null |
| 42 | + |
| 43 | +APP_NAME="${applicationName}" |
| 44 | +APP_BASE_NAME=`basename "\$0"` |
| 45 | + |
| 46 | +UNAME=\$(uname -s) |
| 47 | +if [ x"\$UNAME" == x"Linux" ];then |
| 48 | + TOTAL=\$(cat /proc/meminfo |grep MemTotal |awk -F ' ' '{print \$2}') |
| 49 | + MEM=\$(echo "\$TOTAL/1024/1024*0.8" | bc |awk -F. '{print \$1"g"}') |
| 50 | + JAVA_OPTS='"-Xmx\$MEM" "-Xms\$MEM"' |
| 51 | +fi |
| 52 | + |
| 53 | +# Add default JVM options here. You can also use JAVA_OPTS and ${optsEnvironmentVar} to pass JVM options to this script. |
| 54 | +DEFAULT_JVM_OPTS=${defaultJvmOpts} |
| 55 | + |
| 56 | +# Use the maximum available, or set MAX_FD != -1 to use that value. |
| 57 | +MAX_FD="maximum" |
| 58 | + |
| 59 | +warn () { |
| 60 | + echo "\$*" |
| 61 | +} |
| 62 | + |
| 63 | +die () { |
| 64 | + echo |
| 65 | + echo "\$*" |
| 66 | + echo |
| 67 | + exit 1 |
| 68 | +} |
| 69 | + |
| 70 | +# OS specific support (must be 'true' or 'false'). |
| 71 | +cygwin=false |
| 72 | +msys=false |
| 73 | +darwin=false |
| 74 | +nonstop=false |
| 75 | +case "`uname`" in |
| 76 | + CYGWIN* ) |
| 77 | + cygwin=true |
| 78 | + ;; |
| 79 | + Darwin* ) |
| 80 | + darwin=true |
| 81 | + ;; |
| 82 | + MINGW* ) |
| 83 | + msys=true |
| 84 | + ;; |
| 85 | + NONSTOP* ) |
| 86 | + nonstop=true |
| 87 | + ;; |
| 88 | +esac |
| 89 | + |
| 90 | +CLASSPATH=$classpath |
| 91 | + |
| 92 | +# Determine the Java command to use to start the JVM. |
| 93 | +if [ -n "\$JAVA_HOME" ] ; then |
| 94 | + if [ -x "\$JAVA_HOME/jre/sh/java" ] ; then |
| 95 | + # IBM's JDK on AIX uses strange locations for the executables |
| 96 | + JAVACMD="\$JAVA_HOME/jre/sh/java" |
| 97 | + else |
| 98 | + JAVACMD="\$JAVA_HOME/bin/java" |
| 99 | + fi |
| 100 | + if [ ! -x "\$JAVACMD" ] ; then |
| 101 | + die "ERROR: JAVA_HOME is set to an invalid directory: \$JAVA_HOME |
| 102 | +
|
| 103 | +Please set the JAVA_HOME variable in your environment to match the |
| 104 | +location of your Java installation." |
| 105 | + fi |
| 106 | +else |
| 107 | + JAVACMD="java" |
| 108 | + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. |
| 109 | +
|
| 110 | +Please set the JAVA_HOME variable in your environment to match the |
| 111 | +location of your Java installation." |
| 112 | +fi |
| 113 | + |
| 114 | +# Increase the maximum file descriptors if we can. |
| 115 | +if [ "\$cygwin" = "false" -a "\$darwin" = "false" -a "\$nonstop" = "false" ] ; then |
| 116 | + MAX_FD_LIMIT=`ulimit -H -n` |
| 117 | + if [ \$? -eq 0 ] ; then |
| 118 | + if [ "\$MAX_FD" = "maximum" -o "\$MAX_FD" = "max" ] ; then |
| 119 | + MAX_FD="\$MAX_FD_LIMIT" |
| 120 | + fi |
| 121 | + ulimit -n \$MAX_FD |
| 122 | + if [ \$? -ne 0 ] ; then |
| 123 | + warn "Could not set maximum file descriptor limit: \$MAX_FD" |
| 124 | + fi |
| 125 | + else |
| 126 | + warn "Could not query maximum file descriptor limit: \$MAX_FD_LIMIT" |
| 127 | + fi |
| 128 | +fi |
| 129 | + |
| 130 | +# For Darwin, add options to specify how the application appears in the dock |
| 131 | +if \$darwin; then |
| 132 | + GRADLE_OPTS="\$GRADLE_OPTS \\"-Xdock:name=\$APP_NAME\\" \\"-Xdock:icon=\$APP_HOME/media/gradle.icns\\"" |
| 133 | +fi |
| 134 | + |
| 135 | +# For Cygwin or MSYS, switch paths to Windows format before running java |
| 136 | +if [ "\$cygwin" = "true" -o "\$msys" = "true" ] ; then |
| 137 | + APP_HOME=`cygpath --path --mixed "\$APP_HOME"` |
| 138 | + CLASSPATH=`cygpath --path --mixed "\$CLASSPATH"` |
| 139 | + JAVACMD=`cygpath --unix "\$JAVACMD"` |
| 140 | + |
| 141 | + # We build the pattern for arguments to be converted via cygpath |
| 142 | + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` |
| 143 | + SEP="" |
| 144 | + for dir in \$ROOTDIRSRAW ; do |
| 145 | + ROOTDIRS="\$ROOTDIRS\$SEP\$dir" |
| 146 | + SEP="|" |
| 147 | + done |
| 148 | + OURCYGPATTERN="(^(\$ROOTDIRS))" |
| 149 | + # Add a user-defined pattern to the cygpath arguments |
| 150 | + if [ "\$GRADLE_CYGPATTERN" != "" ] ; then |
| 151 | + OURCYGPATTERN="\$OURCYGPATTERN|(\$GRADLE_CYGPATTERN)" |
| 152 | + fi |
| 153 | + # Now convert the arguments - kludge to limit ourselves to /bin/sh |
| 154 | + i=0 |
| 155 | + for arg in "\$@" ; do |
| 156 | + CHECK=`echo "\$arg"|egrep -c "\$OURCYGPATTERN" -` |
| 157 | + CHECK2=`echo "\$arg"|egrep -c "^-"` ### Determine if an option |
| 158 | + |
| 159 | + if [ \$CHECK -ne 0 ] && [ \$CHECK2 -eq 0 ] ; then ### Added a condition |
| 160 | + eval `echo args\$i`=`cygpath --path --ignore --mixed "\$arg"` |
| 161 | + else |
| 162 | + eval `echo args\$i`="\"\$arg\"" |
| 163 | + fi |
| 164 | + i=`expr \$i + 1` |
| 165 | + done |
| 166 | + case \$i in |
| 167 | + 0) set -- ;; |
| 168 | + 1) set -- "\$args0" ;; |
| 169 | + 2) set -- "\$args0" "\$args1" ;; |
| 170 | + 3) set -- "\$args0" "\$args1" "\$args2" ;; |
| 171 | + 4) set -- "\$args0" "\$args1" "\$args2" "\$args3" ;; |
| 172 | + 5) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" ;; |
| 173 | + 6) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" "\$args5" ;; |
| 174 | + 7) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" "\$args5" "\$args6" ;; |
| 175 | + 8) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" "\$args5" "\$args6" "\$args7" ;; |
| 176 | + 9) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" "\$args5" "\$args6" "\$args7" "\$args8" ;; |
| 177 | + esac |
| 178 | +fi |
| 179 | + |
| 180 | +# Escape application args |
| 181 | +save () { |
| 182 | + for i do printf %s\\\\n "\$i" | sed "s/'/'\\\\\\\\''/g;1s/^/'/;\\\$s/\\\$/' \\\\\\\\/" ; done |
| 183 | + echo " " |
| 184 | +} |
| 185 | +APP_ARGS=`save "\$@"` |
| 186 | + |
| 187 | +# Collect all arguments for the java command, following the shell quoting and substitution rules |
| 188 | +eval set -- \$DEFAULT_JVM_OPTS \$JAVA_OPTS \$${optsEnvironmentVar} <% if ( appNameSystemProperty ) { %>"\"-D${appNameSystemProperty}=\$APP_BASE_NAME\"" <% } %>-classpath "\"\$CLASSPATH\"" ${mainClassName} "\$APP_ARGS" |
| 189 | + |
| 190 | +exec "\$JAVACMD" "\$@" |
0 commit comments