Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 771 | blopes | 1 | #!/bin/sh |
| 2 | |||
| 3 | # Licensed to the Apache Software Foundation (ASF) under one or more |
||
| 4 | # contributor license agreements. See the NOTICE file distributed with |
||
| 5 | # this work for additional information regarding copyright ownership. |
||
| 6 | # The ASF licenses this file to You under the Apache License, Version 2.0 |
||
| 7 | # (the "License"); you may not use this file except in compliance with |
||
| 8 | # the License. You may obtain a copy of the License at |
||
| 9 | # |
||
| 10 | # http://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 | # Commons Daemon wrapper script. |
||
| 20 | # ----------------------------------------------------------------------------- |
||
| 21 | |||
| 22 | # resolve links - $0 may be a softlink |
||
| 23 | PRG="$0" |
||
| 24 | |||
| 25 | while [ -h "$PRG" ]; do |
||
| 26 | ls=`ls -ld "$PRG"` |
||
| 27 | link=`expr "$ls" : '.*-> \(.*\)$'` |
||
| 28 | if expr "$link" : '/.*' > /dev/null; then |
||
| 29 | PRG="$link" |
||
| 30 | else |
||
| 31 | PRG=`dirname "$PRG"`/"$link" |
||
| 32 | fi |
||
| 33 | done |
||
| 34 | |||
| 35 | DIRNAME="`dirname "$PRG"`" |
||
| 36 | PROGRAM="`basename "$PRG"`" |
||
| 37 | while [ ".$1" != . ] |
||
| 38 | do |
||
| 39 | case "$1" in |
||
| 40 | --java-home ) |
||
| 41 | JAVA_HOME="$2" |
||
| 42 | shift; shift; |
||
| 43 | continue |
||
| 44 | ;; |
||
| 45 | --catalina-home ) |
||
| 46 | CATALINA_HOME="$2" |
||
| 47 | shift; shift; |
||
| 48 | continue |
||
| 49 | ;; |
||
| 50 | --catalina-base ) |
||
| 51 | CATALINA_BASE="$2" |
||
| 52 | shift; shift; |
||
| 53 | continue |
||
| 54 | ;; |
||
| 55 | --catalina-pid ) |
||
| 56 | CATALINA_PID="$2" |
||
| 57 | shift; shift; |
||
| 58 | continue |
||
| 59 | ;; |
||
| 60 | --tomcat-user ) |
||
| 61 | TOMCAT_USER="$2" |
||
| 62 | shift; shift; |
||
| 63 | continue |
||
| 64 | ;; |
||
| 65 | --service-start-wait-time ) |
||
| 66 | SERVICE_START_WAIT_TIME="$2" |
||
| 67 | shift; shift; |
||
| 68 | continue |
||
| 69 | ;; |
||
| 70 | * ) |
||
| 71 | break |
||
| 72 | ;; |
||
| 73 | esac |
||
| 74 | done |
||
| 75 | # OS specific support (must be 'true' or 'false'). |
||
| 76 | cygwin=false; |
||
| 77 | darwin=false; |
||
| 78 | case "`uname`" in |
||
| 79 | CYGWIN*) |
||
| 80 | cygwin=true |
||
| 81 | ;; |
||
| 82 | Darwin*) |
||
| 83 | darwin=true |
||
| 84 | ;; |
||
| 85 | esac |
||
| 86 | |||
| 87 | # Use the maximum available, or set MAX_FD != -1 to use that |
||
| 88 | test ".$MAX_FD" = . && MAX_FD="maximum" |
||
| 89 | # Setup parameters for running the jsvc |
||
| 90 | # |
||
| 91 | test ".$TOMCAT_USER" = . && TOMCAT_USER=tomcat |
||
| 92 | # Set JAVA_HOME to working JDK or JRE |
||
| 93 | # If not set we'll try to guess the JAVA_HOME |
||
| 94 | # from java binary if on the PATH |
||
| 95 | # |
||
| 96 | if [ -z "$JAVA_HOME" ]; then |
||
| 97 | JAVA_BIN="`which java 2>/dev/null || type java 2>&1`" |
||
| 98 | while [ -h "$JAVA_BIN" ]; do |
||
| 99 | ls=`ls -ld "$JAVA_BIN"` |
||
| 100 | link=`expr "$ls" : '.*-> \(.*\)$'` |
||
| 101 | if expr "$link" : '/.*' > /dev/null; then |
||
| 102 | JAVA_BIN="$link" |
||
| 103 | else |
||
| 104 | JAVA_BIN="`dirname "$JAVA_BIN"`/$link" |
||
| 105 | fi |
||
| 106 | done |
||
| 107 | test -x "$JAVA_BIN" && JAVA_HOME="`dirname "$JAVA_BIN"`" |
||
| 108 | test ".$JAVA_HOME" != . && JAVA_HOME=`cd "$JAVA_HOME/.." >/dev/null; pwd` |
||
| 109 | else |
||
| 110 | JAVA_BIN="$JAVA_HOME/bin/java" |
||
| 111 | fi |
||
| 112 | |||
| 113 | # Only set CATALINA_HOME if not already set |
||
| 114 | test ".$CATALINA_HOME" = . && CATALINA_HOME=`cd "$DIRNAME/.." >/dev/null; pwd` |
||
| 115 | test ".$CATALINA_BASE" = . && CATALINA_BASE="$CATALINA_HOME" |
||
| 116 | test ".$CATALINA_MAIN" = . && CATALINA_MAIN=org.apache.catalina.startup.Bootstrap |
||
| 117 | # If not explicitly set, look for jsvc in CATALINA_BASE first then CATALINA_HOME |
||
| 118 | if [ -z "$JSVC" ]; then |
||
| 119 | JSVC="$CATALINA_BASE/bin/jsvc" |
||
| 120 | if [ ! -x "$JSVC" ]; then |
||
| 121 | JSVC="$CATALINA_HOME/bin/jsvc" |
||
| 122 | fi |
||
| 123 | fi |
||
| 124 | # Set the default service-start wait time if necessary |
||
| 125 | test ".$SERVICE_START_WAIT_TIME" = . && SERVICE_START_WAIT_TIME=10 |
||
| 126 | |||
| 127 | # Ensure that any user defined CLASSPATH variables are not used on startup, |
||
| 128 | # but allow them to be specified in setenv.sh, in rare case when it is needed. |
||
| 129 | CLASSPATH= |
||
| 130 | JAVA_OPTS= |
||
| 131 | if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then |
||
| 132 | . "$CATALINA_BASE/bin/setenv.sh" |
||
| 133 | elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then |
||
| 134 | . "$CATALINA_HOME/bin/setenv.sh" |
||
| 135 | fi |
||
| 136 | |||
| 137 | # Add on extra jar files to CLASSPATH |
||
| 138 | test ".$CLASSPATH" != . && CLASSPATH="$CLASSPATH:" |
||
| 139 | CLASSPATH="$CLASSPATH$CATALINA_HOME/bin/bootstrap.jar:$CATALINA_HOME/bin/commons-daemon.jar" |
||
| 140 | |||
| 141 | test ".$CATALINA_OUT" = . && CATALINA_OUT="$CATALINA_BASE/logs/catalina-daemon.out" |
||
| 142 | test ".$CATALINA_TMP" = . && CATALINA_TMP="$CATALINA_BASE/temp" |
||
| 143 | |||
| 144 | # Add tomcat-juli.jar to classpath |
||
| 145 | # tomcat-juli.jar can be over-ridden per instance |
||
| 146 | if [ -r "$CATALINA_BASE/bin/tomcat-juli.jar" ] ; then |
||
| 147 | CLASSPATH="$CLASSPATH:$CATALINA_BASE/bin/tomcat-juli.jar" |
||
| 148 | else |
||
| 149 | CLASSPATH="$CLASSPATH:$CATALINA_HOME/bin/tomcat-juli.jar" |
||
| 150 | fi |
||
| 151 | |||
| 152 | # Check for the deprecated LOGGING_CONFIG |
||
| 153 | # Only use it if CATALINA_LOGGING_CONFIG is not set and LOGGING_CONFIG starts with "-D..." |
||
| 154 | if [ -z "$CATALINA_LOGGING_CONFIG" ]; then |
||
| 155 | case $LOGGING_CONFIG in |
||
| 156 | -D*) CATALINA_LOGGING_CONFIG="$LOGGING_CONFIG" |
||
| 157 | esac |
||
| 158 | fi |
||
| 159 | |||
| 160 | # Set juli LogManager config file if it is present and an override has not been issued |
||
| 161 | if [ -z "$CATALINA_LOGGING_CONFIG" ]; then |
||
| 162 | if [ -r "$CATALINA_BASE/conf/logging.properties" ]; then |
||
| 163 | CATALINA_LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties" |
||
| 164 | else |
||
| 165 | # Bugzilla 45585 |
||
| 166 | CATALINA_LOGGING_CONFIG="-Dnop" |
||
| 167 | fi |
||
| 168 | fi |
||
| 169 | |||
| 170 | test ".$LOGGING_MANAGER" = . && LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" |
||
| 171 | JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER" |
||
| 172 | |||
| 173 | # Set -pidfile |
||
| 174 | test ".$CATALINA_PID" = . && CATALINA_PID="$CATALINA_BASE/logs/catalina-daemon.pid" |
||
| 175 | |||
| 176 | # Increase the maximum file descriptors if we can |
||
| 177 | if [ "$cygwin" = "false" ]; then |
||
| 178 | MAX_FD_LIMIT=`ulimit -H -n` |
||
| 179 | if [ "$?" -eq 0 ]; then |
||
| 180 | # Darwin does not allow RLIMIT_INFINITY on file soft limit |
||
| 181 | if [ "$darwin" = "true" ] && [ "$MAX_FD_LIMIT" = "unlimited" ]; then |
||
| 182 | MAX_FD_LIMIT=`/usr/sbin/sysctl -n kern.maxfilesperproc` |
||
| 183 | fi |
||
| 184 | test ".$MAX_FD" = ".maximum" && MAX_FD="$MAX_FD_LIMIT" |
||
| 185 | ulimit -n $MAX_FD |
||
| 186 | if [ "$?" -ne 0 ]; then |
||
| 187 | echo "$PROGRAM: Could not set maximum file descriptor limit: $MAX_FD" |
||
| 188 | fi |
||
| 189 | else |
||
| 190 | echo "$PROGRAM: Could not query system maximum file descriptor limit: $MAX_FD_LIMIT" |
||
| 191 | fi |
||
| 192 | fi |
||
| 193 | |||
| 194 | # Set UMASK unless it has been overridden |
||
| 195 | if [ -z "$UMASK" ]; then |
||
| 196 | UMASK="0027" |
||
| 197 | fi |
||
| 198 | umask $UMASK |
||
| 199 | |||
| 200 | # Java 9 no longer supports the java.endorsed.dirs |
||
| 201 | # system property. Only try to use it if |
||
| 202 | # JAVA_ENDORSED_DIRS was explicitly set |
||
| 203 | # or CATALINA_HOME/endorsed exists. |
||
| 204 | ENDORSED_PROP=ignore.endorsed.dirs |
||
| 205 | if [ -n "$JAVA_ENDORSED_DIRS" ]; then |
||
| 206 | ENDORSED_PROP=java.endorsed.dirs |
||
| 207 | fi |
||
| 208 | if [ -d "$CATALINA_HOME/endorsed" ]; then |
||
| 209 | ENDORSED_PROP=java.endorsed.dirs |
||
| 210 | fi |
||
| 211 | |||
| 212 | # ----- Execute The Requested Command ----------------------------------------- |
||
| 213 | case "$1" in |
||
| 214 | run ) |
||
| 215 | shift |
||
| 216 | eval exec "\"$JSVC\"" $* \ |
||
| 217 | "$JSVC_OPTS" \ |
||
| 218 | -java-home "\"$JAVA_HOME\"" \ |
||
| 219 | -pidfile "\"$CATALINA_PID\"" \ |
||
| 220 | -wait $SERVICE_START_WAIT_TIME \ |
||
| 221 | -umask $UMASK \ |
||
| 222 | -nodetach \ |
||
| 223 | -outfile "\"&1\"" \ |
||
| 224 | -errfile "\"&2\"" \ |
||
| 225 | -classpath "\"$CLASSPATH\"" \ |
||
| 226 | "\"$CATALINA_LOGGING_CONFIG\"" "$JAVA_OPTS" "$CATALINA_OPTS" \ |
||
| 227 | -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \ |
||
| 228 | -Dcatalina.base="\"$CATALINA_BASE\"" \ |
||
| 229 | -Dcatalina.home="\"$CATALINA_HOME\"" \ |
||
| 230 | -Djava.io.tmpdir="\"$CATALINA_TMP\"" \ |
||
| 231 | $CATALINA_MAIN |
||
| 232 | exit $? |
||
| 233 | ;; |
||
| 234 | start ) |
||
| 235 | eval "\"$JSVC\"" \ |
||
| 236 | "$JSVC_OPTS" \ |
||
| 237 | -java-home "\"$JAVA_HOME\"" \ |
||
| 238 | -user $TOMCAT_USER \ |
||
| 239 | -pidfile "\"$CATALINA_PID\"" \ |
||
| 240 | -wait $SERVICE_START_WAIT_TIME \ |
||
| 241 | -umask $UMASK \ |
||
| 242 | -outfile "\"$CATALINA_OUT\"" \ |
||
| 243 | -errfile "\"&1\"" \ |
||
| 244 | -classpath "\"$CLASSPATH\"" \ |
||
| 245 | "\"$CATALINA_LOGGING_CONFIG\"" "$JAVA_OPTS" "$CATALINA_OPTS" \ |
||
| 246 | -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \ |
||
| 247 | -Dcatalina.base="\"$CATALINA_BASE\"" \ |
||
| 248 | -Dcatalina.home="\"$CATALINA_HOME\"" \ |
||
| 249 | -Djava.io.tmpdir="\"$CATALINA_TMP\"" \ |
||
| 250 | $CATALINA_MAIN |
||
| 251 | exit $? |
||
| 252 | ;; |
||
| 253 | stop ) |
||
| 254 | eval "\"$JSVC\"" \ |
||
| 255 | "$JSVC_OPTS" \ |
||
| 256 | -stop \ |
||
| 257 | -pidfile "\"$CATALINA_PID\"" \ |
||
| 258 | -classpath "\"$CLASSPATH\"" \ |
||
| 259 | -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \ |
||
| 260 | -Dcatalina.base="\"$CATALINA_BASE\"" \ |
||
| 261 | -Dcatalina.home="\"$CATALINA_HOME\"" \ |
||
| 262 | -Djava.io.tmpdir="\"$CATALINA_TMP\"" \ |
||
| 263 | $CATALINA_MAIN |
||
| 264 | exit $? |
||
| 265 | ;; |
||
| 266 | version ) |
||
| 267 | "$JSVC" \ |
||
| 268 | -java-home "$JAVA_HOME" \ |
||
| 269 | -pidfile "$CATALINA_PID" \ |
||
| 270 | -classpath "$CLASSPATH" \ |
||
| 271 | -errfile "&2" \ |
||
| 272 | -version \ |
||
| 273 | -check \ |
||
| 274 | $CATALINA_MAIN |
||
| 275 | if [ "$?" = 0 ]; then |
||
| 276 | "$JAVA_BIN" \ |
||
| 277 | -classpath "$CATALINA_HOME/lib/catalina.jar" \ |
||
| 278 | org.apache.catalina.util.ServerInfo |
||
| 279 | fi |
||
| 280 | exit $? |
||
| 281 | ;; |
||
| 282 | * ) |
||
| 283 | echo "Unknown command: '$1'" |
||
| 284 | echo "Usage: $PROGRAM ( commands ... )" |
||
| 285 | echo "commands:" |
||
| 286 | echo " run Start Tomcat without detaching from console" |
||
| 287 | echo " start Start Tomcat" |
||
| 288 | echo " stop Stop Tomcat" |
||
| 289 | echo " version What version of commons daemon and Tomcat" |
||
| 290 | echo " are you running?" |
||
| 291 | exit 1 |
||
| 292 | ;; |
||
| 293 | esac |