blob: 30e147bf6e88758f3d646b8521568114f296ccf3 [file] [log] [blame]
刘洪青65827522016-10-19 16:10:39 +08001@echo off
2rem Licensed to the Apache Software Foundation (ASF) under one or more
3rem contributor license agreements. See the NOTICE file distributed with
4rem this work for additional information regarding copyright ownership.
5rem The ASF licenses this file to You under the Apache License, Version 2.0
6rem (the "License"); you may not use this file except in compliance with
7rem the License. You may obtain a copy of the License at
8rem
9rem http://www.apache.org/licenses/LICENSE-2.0
10rem
11rem Unless required by applicable law or agreed to in writing, software
12rem distributed under the License is distributed on an "AS IS" BASIS,
13rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14rem See the License for the specific language governing permissions and
15rem limitations under the License.
16
17rem ---------------------------------------------------------------------------
18rem Start/Stop Script for the CATALINA Server
19rem
20rem Environment Variable Prerequisites
21rem
22rem Do not set the variables in this script. Instead put them into a script
23rem setenv.bat in CATALINA_BASE/bin to keep your customizations separate.
24rem
25rem CATALINA_HOME May point at your Catalina "build" directory.
26rem
27rem CATALINA_BASE (Optional) Base directory for resolving dynamic portions
28rem of a Catalina installation. If not present, resolves to
29rem the same directory that CATALINA_HOME points to.
30rem
31rem CATALINA_OPTS (Optional) Java runtime options used when the "start",
32rem "run" or "debug" command is executed.
33rem Include here and not in JAVA_OPTS all options, that should
34rem only be used by Tomcat itself, not by the stop process,
35rem the version command etc.
36rem Examples are heap size, GC logging, JMX ports etc.
37rem
38rem CATALINA_TMPDIR (Optional) Directory path location of temporary directory
39rem the JVM should use (java.io.tmpdir). Defaults to
40rem %CATALINA_BASE%\temp.
41rem
42rem JAVA_HOME Must point at your Java Development Kit installation.
43rem Required to run the with the "debug" argument.
44rem
45rem JRE_HOME Must point at your Java Runtime installation.
46rem Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME
47rem are both set, JRE_HOME is used.
48rem
49rem JAVA_OPTS (Optional) Java runtime options used when any command
50rem is executed.
51rem Include here and not in CATALINA_OPTS all options, that
52rem should be used by Tomcat and also by the stop process,
53rem the version command etc.
54rem Most options should go into CATALINA_OPTS.
55rem
56rem JAVA_ENDORSED_DIRS (Optional) Lists of of semi-colon separated directories
57rem containing some jars in order to allow replacement of APIs
58rem created outside of the JCP (i.e. DOM and SAX from W3C).
59rem It can also be used to update the XML parser implementation.
60rem Defaults to $CATALINA_HOME/endorsed.
61rem
62rem JPDA_TRANSPORT (Optional) JPDA transport used when the "jpda start"
63rem command is executed. The default is "dt_socket".
64rem
65rem JPDA_ADDRESS (Optional) Java runtime options used when the "jpda start"
66rem command is executed. The default is 8000.
67rem
68rem JPDA_SUSPEND (Optional) Java runtime options used when the "jpda start"
69rem command is executed. Specifies whether JVM should suspend
70rem execution immediately after startup. Default is "n".
71rem
72rem JPDA_OPTS (Optional) Java runtime options used when the "jpda start"
73rem command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
74rem and JPDA_SUSPEND are ignored. Thus, all required jpda
75rem options MUST be specified. The default is:
76rem
77rem -agentlib:jdwp=transport=%JPDA_TRANSPORT%,
78rem address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
79rem
80rem JSSE_OPTS (Optional) Java runtime options used to control the TLS
81rem implementation when JSSE is used. Default is:
82rem "-Djdk.tls.ephemeralDHKeySize=2048"
83rem
84rem LOGGING_CONFIG (Optional) Override Tomcat's logging config file
85rem Example (all one line)
86rem set LOGGING_CONFIG="-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties"
87rem
88rem LOGGING_MANAGER (Optional) Override Tomcat's logging manager
89rem Example (all one line)
90rem set LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
91rem
92rem TITLE (Optional) Specify the title of Tomcat window. The default
93rem TITLE is Tomcat if it's not specified.
94rem Example (all one line)
95rem set TITLE=Tomcat.Cluster#1.Server#1 [%DATE% %TIME%]
96rem ---------------------------------------------------------------------------
97
98setlocal
99
100rem Suppress Terminate batch job on CTRL+C
101if not ""%1"" == ""run"" goto mainEntry
102if "%TEMP%" == "" goto mainEntry
103if exist "%TEMP%\%~nx0.run" goto mainEntry
104echo Y>"%TEMP%\%~nx0.run"
105if not exist "%TEMP%\%~nx0.run" goto mainEntry
106echo Y>"%TEMP%\%~nx0.Y"
107call "%~f0" %* <"%TEMP%\%~nx0.Y"
108rem Use provided errorlevel
109set RETVAL=%ERRORLEVEL%
110del /Q "%TEMP%\%~nx0.Y" >NUL 2>&1
111exit /B %RETVAL%
112:mainEntry
113del /Q "%TEMP%\%~nx0.run" >NUL 2>&1
114
115rem Guess CATALINA_HOME if not defined
116set "CURRENT_DIR=%cd%"
117if not "%CATALINA_HOME%" == "" goto gotHome
118set "CATALINA_HOME=%CURRENT_DIR%"
119if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
120cd ..
121set "CATALINA_HOME=%cd%"
122cd "%CURRENT_DIR%"
123:gotHome
124
125if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
126echo The CATALINA_HOME environment variable is not defined correctly
127echo This environment variable is needed to run this program
128goto end
129:okHome
130
131rem Copy CATALINA_BASE from CATALINA_HOME if not defined
132if not "%CATALINA_BASE%" == "" goto gotBase
133set "CATALINA_BASE=%CATALINA_HOME%"
134:gotBase
135
136rem Ensure that any user defined CLASSPATH variables are not used on startup,
137rem but allow them to be specified in setenv.bat, in rare case when it is needed.
138set CLASSPATH=
139
140rem Get standard environment variables
141if not exist "%CATALINA_BASE%\bin\setenv.bat" goto checkSetenvHome
142call "%CATALINA_BASE%\bin\setenv.bat"
143goto setenvDone
144:checkSetenvHome
145if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat"
146:setenvDone
147
148rem Get standard Java environment variables
149if exist "%CATALINA_HOME%\bin\setclasspath.bat" goto okSetclasspath
150echo Cannot find "%CATALINA_HOME%\bin\setclasspath.bat"
151echo This file is needed to run this program
152goto end
153:okSetclasspath
154call "%CATALINA_HOME%\bin\setclasspath.bat" %1
155if errorlevel 1 goto end
156
157rem Add on extra jar file to CLASSPATH
158rem Note that there are no quotes as we do not want to introduce random
159rem quotes into the CLASSPATH
160if "%CLASSPATH%" == "" goto emptyClasspath
161set "CLASSPATH=%CLASSPATH%;"
162:emptyClasspath
163set "CLASSPATH=%CLASSPATH%%CATALINA_HOME%\bin\bootstrap.jar"
164
165if not "%CATALINA_TMPDIR%" == "" goto gotTmpdir
166set "CATALINA_TMPDIR=%CATALINA_BASE%\temp"
167:gotTmpdir
168
169rem Add tomcat-juli.jar to classpath
170rem tomcat-juli.jar can be over-ridden per instance
171if not exist "%CATALINA_BASE%\bin\tomcat-juli.jar" goto juliClasspathHome
172set "CLASSPATH=%CLASSPATH%;%CATALINA_BASE%\bin\tomcat-juli.jar"
173goto juliClasspathDone
174:juliClasspathHome
175set "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\bin\tomcat-juli.jar"
176:juliClasspathDone
177
178if not "%JSSE_OPTS%" == "" goto gotJsseOpts
179set JSSE_OPTS="-Djdk.tls.ephemeralDHKeySize=2048"
180:gotJsseOpts
181set "JAVA_OPTS=%JAVA_OPTS% %JSSE_OPTS%"
182
183if not "%LOGGING_CONFIG%" == "" goto noJuliConfig
184set LOGGING_CONFIG=-Dnop
185if not exist "%CATALINA_BASE%\conf\logging.properties" goto noJuliConfig
186set LOGGING_CONFIG=-Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties"
187:noJuliConfig
188set "JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG%"
189
190if not "%LOGGING_MANAGER%" == "" goto noJuliManager
191set LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
192:noJuliManager
193set "JAVA_OPTS=%JAVA_OPTS% %LOGGING_MANAGER%"
194
195rem ----- Execute The Requested Command ---------------------------------------
196
197echo Using CATALINA_BASE: "%CATALINA_BASE%"
198echo Using CATALINA_HOME: "%CATALINA_HOME%"
199echo Using CATALINA_TMPDIR: "%CATALINA_TMPDIR%"
200if ""%1"" == ""debug"" goto use_jdk
201echo Using JRE_HOME: "%JRE_HOME%"
202goto java_dir_displayed
203:use_jdk
204echo Using JAVA_HOME: "%JAVA_HOME%"
205:java_dir_displayed
206echo Using CLASSPATH: "%CLASSPATH%"
207
208set _EXECJAVA=%_RUNJAVA%
209set MAINCLASS=org.apache.catalina.startup.Bootstrap
210set ACTION=start
211set SECURITY_POLICY_FILE=
212set DEBUG_OPTS=
213set JPDA=
214
215if not ""%1"" == ""jpda"" goto noJpda
216set JPDA=jpda
217if not "%JPDA_TRANSPORT%" == "" goto gotJpdaTransport
218set JPDA_TRANSPORT=dt_socket
219:gotJpdaTransport
220if not "%JPDA_ADDRESS%" == "" goto gotJpdaAddress
221set JPDA_ADDRESS=8000
222:gotJpdaAddress
223if not "%JPDA_SUSPEND%" == "" goto gotJpdaSuspend
224set JPDA_SUSPEND=n
225:gotJpdaSuspend
226if not "%JPDA_OPTS%" == "" goto gotJpdaOpts
227set JPDA_OPTS=-agentlib:jdwp=transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
228:gotJpdaOpts
229shift
230:noJpda
231
232if ""%1"" == ""debug"" goto doDebug
233if ""%1"" == ""run"" goto doRun
234if ""%1"" == ""start"" goto doStart
235if ""%1"" == ""stop"" goto doStop
236if ""%1"" == ""configtest"" goto doConfigTest
237if ""%1"" == ""version"" goto doVersion
238
239echo Usage: catalina ( commands ... )
240echo commands:
241echo debug Start Catalina in a debugger
242echo debug -security Debug Catalina with a security manager
243echo jpda start Start Catalina under JPDA debugger
244echo run Start Catalina in the current window
245echo run -security Start in the current window with security manager
246echo start Start Catalina in a separate window
247echo start -security Start in a separate window with security manager
248echo stop Stop Catalina
249echo configtest Run a basic syntax check on server.xml
250echo version What version of tomcat are you running?
251goto end
252
253:doDebug
254shift
255set _EXECJAVA=%_RUNJDB%
256set DEBUG_OPTS=-sourcepath "%CATALINA_HOME%\..\..\java"
257if not ""%1"" == ""-security"" goto execCmd
258shift
259echo Using Security Manager
260set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"
261goto execCmd
262
263:doRun
264shift
265if not ""%1"" == ""-security"" goto execCmd
266shift
267echo Using Security Manager
268set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"
269goto execCmd
270
271:doStart
272shift
273if "%TITLE%" == "" set TITLE=Tomcat
274set _EXECJAVA=start "%TITLE%" %_RUNJAVA%
275if not ""%1"" == ""-security"" goto execCmd
276shift
277echo Using Security Manager
278set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"
279goto execCmd
280
281:doStop
282shift
283set ACTION=stop
284set CATALINA_OPTS=
285goto execCmd
286
287:doConfigTest
288shift
289set ACTION=configtest
290set CATALINA_OPTS=
291goto execCmd
292
293:doVersion
294%_EXECJAVA% -classpath "%CATALINA_HOME%\lib\catalina.jar" org.apache.catalina.util.ServerInfo
295goto end
296
297
298:execCmd
299rem Get remaining unshifted command line arguments and save them in the
300set CMD_LINE_ARGS=
301:setArgs
302if ""%1""=="""" goto doneSetArgs
303set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
304shift
305goto setArgs
306:doneSetArgs
307
308rem Execute Java with the applicable properties
309if not "%JPDA%" == "" goto doJpda
310if not "%SECURITY_POLICY_FILE%" == "" goto doSecurity
311%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
312goto end
313:doSecurity
314%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager -Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
315goto end
316:doJpda
317if not "%SECURITY_POLICY_FILE%" == "" goto doSecurityJpda
318%_EXECJAVA% %JAVA_OPTS% %JPDA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
319goto end
320:doSecurityJpda
321%_EXECJAVA% %JAVA_OPTS% %JPDA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager -Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
322goto end
323
324:end