blob: fc18f761b90285d87fabb2718de2b464a4cd165f [file] [log] [blame]
Hongqing Liufd5ee812014-05-10 16:32:51 +08001#!/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
23ARG0="$0"
24while [ -h "$ARG0" ]; do
25 ls=`ls -ld "$ARG0"`
26 link=`expr "$ls" : '.*-> \(.*\)$'`
27 if expr "$link" : '/.*' > /dev/null; then
28 ARG0="$link"
29 else
30 ARG0="`dirname $ARG0`/$link"
31 fi
32done
33DIRNAME="`dirname $ARG0`"
34PROGRAM="`basename $ARG0`"
35while [ ".$1" != . ]
36do
37 case "$1" in
38 --java-home )
39 JAVA_HOME="$2"
40 shift; shift;
41 continue
42 ;;
43 --catalina-home )
44 CATALINA_HOME="$2"
45 shift; shift;
46 continue
47 ;;
48 --catalina-base )
49 CATALINA_BASE="$2"
50 shift; shift;
51 continue
52 ;;
53 --catalina-pid )
54 CATALINA_PID="$2"
55 shift; shift;
56 continue
57 ;;
58 --tomcat-user )
59 TOMCAT_USER="$2"
60 shift; shift;
61 continue
62 ;;
63 --service-start-wait-time )
64 SERVICE_START_WAIT_TIME="$2"
65 shift; shift;
66 continue
67 ;;
68 * )
69 break
70 ;;
71 esac
72done
73# OS specific support (must be 'true' or 'false').
74cygwin=false;
75darwin=false;
76case "`uname`" in
77 CYGWIN*)
78 cygwin=true
79 ;;
80 Darwin*)
81 darwin=true
82 ;;
83esac
84
85# Use the maximum available, or set MAX_FD != -1 to use that
86test ".$MAX_FD" = . && MAX_FD="maximum"
87# Setup parameters for running the jsvc
88#
89test ".$TOMCAT_USER" = . && TOMCAT_USER=tomcat
90# Set JAVA_HOME to working JDK or JRE
91# JAVA_HOME=/opt/jdk-1.6.0.22
92# If not set we'll try to guess the JAVA_HOME
93# from java binary if on the PATH
94#
95if [ -z "$JAVA_HOME" ]; then
96 JAVA_BIN="`which java 2>/dev/null || type java 2>&1`"
97 test -x "$JAVA_BIN" && JAVA_HOME="`dirname $JAVA_BIN`"
98 test ".$JAVA_HOME" != . && JAVA_HOME=`cd "$JAVA_HOME/.." >/dev/null; pwd`
99else
100 JAVA_BIN="$JAVA_HOME/bin/java"
101fi
102
103# Only set CATALINA_HOME if not already set
104test ".$CATALINA_HOME" = . && CATALINA_HOME=`cd "$DIRNAME/.." >/dev/null; pwd`
105test ".$CATALINA_BASE" = . && CATALINA_BASE="$CATALINA_HOME"
106test ".$CATALINA_MAIN" = . && CATALINA_MAIN=org.apache.catalina.startup.Bootstrap
107test ".$JSVC" = . && JSVC="$CATALINA_BASE/bin/jsvc"
108# Set the default service-start wait time if necessary
109test ".$SERVICE_START_WAIT_TIME" = . && SERVICE_START_WAIT_TIME=10
110
111# Ensure that any user defined CLASSPATH variables are not used on startup,
112# but allow them to be specified in setenv.sh, in rare case when it is needed.
113CLASSPATH=
114JAVA_OPTS=
115if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
116 . "$CATALINA_BASE/bin/setenv.sh"
117elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
118 . "$CATALINA_HOME/bin/setenv.sh"
119fi
120
121# Add on extra jar files to CLASSPATH
122# tomcat-juli.jar can be over-ridden per instance
123test ".$CLASSPATH" != . && CLASSPATH="${CLASSPATH}:"
124if [ "$CATALINA_BASE" != "$CATALINA_HOME" ] && [ -r "$CATALINA_BASE/bin/tomcat-juli.jar" ] ; then
125 CLASSPATH="$CLASSPATH$CATALINA_BASE/bin/tomcat-juli.jar:$CATALINA_HOME/bin/commons-daemon.jar:$CATALINA_HOME/bin/bootstrap.jar"
126else
127 CLASSPATH="$CLASSPATH$CATALINA_HOME/bin/commons-daemon.jar:$CATALINA_HOME/bin/bootstrap.jar"
128fi
129
130test ".$CATALINA_OUT" = . && CATALINA_OUT="$CATALINA_BASE/logs/catalina-daemon.out"
131test ".$CATALINA_TMP" = . && CATALINA_TMP="$CATALINA_BASE/temp"
132
133# Set juli LogManager config file if it is present and an override has not been issued
134if [ -z "$LOGGING_CONFIG" ]; then
135 if [ -r "$CATALINA_BASE/conf/logging.properties" ]; then
136 LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
137 else
138 # Bugzilla 45585
139 LOGGING_CONFIG="-Dnop"
140 fi
141fi
142
143test ".$LOGGING_MANAGER" = . && LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
144JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER"
145
146# Set -pidfile
147test ".$CATALINA_PID" = . && CATALINA_PID="$CATALINA_BASE/logs/catalina-daemon.pid"
148
149# Increase the maximum file descriptors if we can
150if [ "$cygwin" = "false" ]; then
151 MAX_FD_LIMIT=`ulimit -H -n`
152 if [ "$?" -eq 0 ]; then
153 # Darwin does not allow RLIMIT_INFINITY on file soft limit
154 if [ "$darwin" = "true" -a "$MAX_FD_LIMIT" = "unlimited" ]; then
155 MAX_FD_LIMIT=`/usr/sbin/sysctl -n kern.maxfilesperproc`
156 fi
157 test ".$MAX_FD" = ".maximum" && MAX_FD="$MAX_FD_LIMIT"
158 ulimit -n $MAX_FD
159 if [ "$?" -ne 0 ]; then
160 echo "$PROGRAM: Could not set maximum file descriptor limit: $MAX_FD"
161 fi
162 else
163 echo "$PROGRAM: Could not query system maximum file descriptor limit: $MAX_FD_LIMIT"
164 fi
165fi
166
167# ----- Execute The Requested Command -----------------------------------------
168case "$1" in
169 run )
170 shift
171 "$JSVC" $* \
172 $JSVC_OPTS \
173 -java-home "$JAVA_HOME" \
174 -pidfile "$CATALINA_PID" \
175 -wait "$SERVICE_START_WAIT_TIME" \
176 -nodetach \
177 -outfile "&1" \
178 -errfile "&2" \
179 -classpath "$CLASSPATH" \
180 "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
181 -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" \
182 -Dcatalina.base="$CATALINA_BASE" \
183 -Dcatalina.home="$CATALINA_HOME" \
184 -Djava.io.tmpdir="$CATALINA_TMP" \
185 $CATALINA_MAIN
186 exit $?
187 ;;
188 start )
189 "$JSVC" $JSVC_OPTS \
190 -java-home "$JAVA_HOME" \
191 -user $TOMCAT_USER \
192 -pidfile "$CATALINA_PID" \
193 -wait "$SERVICE_START_WAIT_TIME" \
194 -outfile "$CATALINA_OUT" \
195 -errfile "&1" \
196 -classpath "$CLASSPATH" \
197 "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
198 -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" \
199 -Dcatalina.base="$CATALINA_BASE" \
200 -Dcatalina.home="$CATALINA_HOME" \
201 -Djava.io.tmpdir="$CATALINA_TMP" \
202 $CATALINA_MAIN
203 exit $?
204 ;;
205 stop )
206 "$JSVC" $JSVC_OPTS \
207 -stop \
208 -pidfile "$CATALINA_PID" \
209 -classpath "$CLASSPATH" \
210 -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" \
211 -Dcatalina.base="$CATALINA_BASE" \
212 -Dcatalina.home="$CATALINA_HOME" \
213 -Djava.io.tmpdir="$CATALINA_TMP" \
214 $CATALINA_MAIN
215 exit $?
216 ;;
217 version )
218 "$JSVC" \
219 -java-home "$JAVA_HOME" \
220 -pidfile "$CATALINA_PID" \
221 -classpath "$CLASSPATH" \
222 -errfile "&2" \
223 -version \
224 -check \
225 $CATALINA_MAIN
226 if [ "$?" = 0 ]; then
227 "$JAVA_BIN" \
228 -classpath "$CATALINA_HOME/lib/catalina.jar" \
229 org.apache.catalina.util.ServerInfo
230 fi
231 exit $?
232 ;;
233 * )
234 echo "Unknown command: \`$1'"
235 echo "Usage: $PROGRAM ( commands ... )"
236 echo "commands:"
237 echo " run Start Tomcat without detaching from console"
238 echo " start Start Tomcat"
239 echo " stop Stop Tomcat"
240 echo " version What version of commons daemon and Tomcat"
241 echo " are you running?"
242 exit 1
243 ;;
244esac