blob: 859ca9b20fc9e2d1753fe60ee3c57f1a8179fe64 [file] [log] [blame]
Hongqing Liufd5ee812014-05-10 16:32:51 +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
Hongqing Liufd5ee812014-05-10 16:32:51 +080017rem ---------------------------------------------------------------------------
18rem Start/Stop Script for the CATALINA Server
19rem
20rem Environment Variable Prerequisites
21rem
刘洪青6266f992017-05-15 21:21:03 +080022rem 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 WHEN RUNNING TOMCAT AS A WINDOWS SERVICE:
26rem Note that the environment variables that affect the behavior of this
27rem script will have no effect at all on Windows Services. As such, any
28rem local customizations made in a CATALINA_BASE/bin/setenv.bat script
29rem will also have no effect on Tomcat when launched as a Windows Service.
30rem The configuration that controls Windows Services is stored in the Windows
31rem Registry, and is most conveniently maintained using the "tomcatXw.exe"
32rem maintenance utility, where "X" is the major version of Tomcat you are
33rem running.
34rem
Hongqing Liufd5ee812014-05-10 16:32:51 +080035rem CATALINA_HOME May point at your Catalina "build" directory.
36rem
37rem CATALINA_BASE (Optional) Base directory for resolving dynamic portions
38rem of a Catalina installation. If not present, resolves to
39rem the same directory that CATALINA_HOME points to.
40rem
41rem CATALINA_OPTS (Optional) Java runtime options used when the "start",
刘洪青6266f992017-05-15 21:21:03 +080042rem "run" or "debug" command is executed.
43rem Include here and not in JAVA_OPTS all options, that should
44rem only be used by Tomcat itself, not by the stop process,
45rem the version command etc.
46rem Examples are heap size, GC logging, JMX ports etc.
Hongqing Liufd5ee812014-05-10 16:32:51 +080047rem
48rem CATALINA_TMPDIR (Optional) Directory path location of temporary directory
49rem the JVM should use (java.io.tmpdir). Defaults to
50rem %CATALINA_BASE%\temp.
51rem
52rem JAVA_HOME Must point at your Java Development Kit installation.
53rem Required to run the with the "debug" argument.
54rem
55rem JRE_HOME Must point at your Java Runtime installation.
刘洪青6266f992017-05-15 21:21:03 +080056rem Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME
57rem are both set, JRE_HOME is used.
Hongqing Liufd5ee812014-05-10 16:32:51 +080058rem
刘洪青6266f992017-05-15 21:21:03 +080059rem JAVA_OPTS (Optional) Java runtime options used when any command
60rem is executed.
61rem Include here and not in CATALINA_OPTS all options, that
62rem should be used by Tomcat and also by the stop process,
63rem the version command etc.
64rem Most options should go into CATALINA_OPTS.
Hongqing Liufd5ee812014-05-10 16:32:51 +080065rem
66rem JAVA_ENDORSED_DIRS (Optional) Lists of of semi-colon separated directories
刘洪青6266f992017-05-15 21:21:03 +080067rem containing some jars in order to allow replacement of APIs
68rem created outside of the JCP (i.e. DOM and SAX from W3C).
Hongqing Liufd5ee812014-05-10 16:32:51 +080069rem It can also be used to update the XML parser implementation.
70rem Defaults to $CATALINA_HOME/endorsed.
71rem
72rem JPDA_TRANSPORT (Optional) JPDA transport used when the "jpda start"
73rem command is executed. The default is "dt_socket".
74rem
75rem JPDA_ADDRESS (Optional) Java runtime options used when the "jpda start"
76rem command is executed. The default is 8000.
77rem
78rem JPDA_SUSPEND (Optional) Java runtime options used when the "jpda start"
79rem command is executed. Specifies whether JVM should suspend
80rem execution immediately after startup. Default is "n".
81rem
82rem JPDA_OPTS (Optional) Java runtime options used when the "jpda start"
83rem command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
84rem and JPDA_SUSPEND are ignored. Thus, all required jpda
85rem options MUST be specified. The default is:
86rem
87rem -agentlib:jdwp=transport=%JPDA_TRANSPORT%,
88rem address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
89rem
刘洪青6266f992017-05-15 21:21:03 +080090rem JSSE_OPTS (Optional) Java runtime options used to control the TLS
91rem implementation when JSSE is used. Default is:
92rem "-Djdk.tls.ephemeralDHKeySize=2048"
93rem
Hongqing Liufd5ee812014-05-10 16:32:51 +080094rem LOGGING_CONFIG (Optional) Override Tomcat's logging config file
95rem Example (all one line)
96rem set LOGGING_CONFIG="-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties"
97rem
刘洪青6266f992017-05-15 21:21:03 +080098rem LOGGING_MANAGER (Optional) Override Tomcat's logging manager
Hongqing Liufd5ee812014-05-10 16:32:51 +080099rem Example (all one line)
100rem set LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
101rem
102rem TITLE (Optional) Specify the title of Tomcat window. The default
103rem TITLE is Tomcat if it's not specified.
104rem Example (all one line)
105rem set TITLE=Tomcat.Cluster#1.Server#1 [%DATE% %TIME%]
106rem ---------------------------------------------------------------------------
107
刘洪青6266f992017-05-15 21:21:03 +0800108setlocal
109
110rem Suppress Terminate batch job on CTRL+C
111if not ""%1"" == ""run"" goto mainEntry
112if "%TEMP%" == "" goto mainEntry
113if exist "%TEMP%\%~nx0.run" goto mainEntry
114echo Y>"%TEMP%\%~nx0.run"
115if not exist "%TEMP%\%~nx0.run" goto mainEntry
116echo Y>"%TEMP%\%~nx0.Y"
117call "%~f0" %* <"%TEMP%\%~nx0.Y"
118rem Use provided errorlevel
119set RETVAL=%ERRORLEVEL%
120del /Q "%TEMP%\%~nx0.Y" >NUL 2>&1
121exit /B %RETVAL%
122:mainEntry
123del /Q "%TEMP%\%~nx0.run" >NUL 2>&1
124
Hongqing Liufd5ee812014-05-10 16:32:51 +0800125rem Guess CATALINA_HOME if not defined
126set "CURRENT_DIR=%cd%"
127if not "%CATALINA_HOME%" == "" goto gotHome
128set "CATALINA_HOME=%CURRENT_DIR%"
129if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
130cd ..
131set "CATALINA_HOME=%cd%"
132cd "%CURRENT_DIR%"
133:gotHome
刘洪青6266f992017-05-15 21:21:03 +0800134
Hongqing Liufd5ee812014-05-10 16:32:51 +0800135if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
136echo The CATALINA_HOME environment variable is not defined correctly
137echo This environment variable is needed to run this program
138goto end
139:okHome
140
141rem Copy CATALINA_BASE from CATALINA_HOME if not defined
142if not "%CATALINA_BASE%" == "" goto gotBase
143set "CATALINA_BASE=%CATALINA_HOME%"
144:gotBase
145
146rem Ensure that any user defined CLASSPATH variables are not used on startup,
147rem but allow them to be specified in setenv.bat, in rare case when it is needed.
148set CLASSPATH=
149
150rem Get standard environment variables
151if not exist "%CATALINA_BASE%\bin\setenv.bat" goto checkSetenvHome
152call "%CATALINA_BASE%\bin\setenv.bat"
153goto setenvDone
154:checkSetenvHome
155if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat"
156:setenvDone
157
158rem Get standard Java environment variables
159if exist "%CATALINA_HOME%\bin\setclasspath.bat" goto okSetclasspath
160echo Cannot find "%CATALINA_HOME%\bin\setclasspath.bat"
161echo This file is needed to run this program
162goto end
163:okSetclasspath
Hongqing Liufd5ee812014-05-10 16:32:51 +0800164call "%CATALINA_HOME%\bin\setclasspath.bat" %1
165if errorlevel 1 goto end
166
刘洪青6266f992017-05-15 21:21:03 +0800167rem Add on extra jar file to CLASSPATH
Hongqing Liufd5ee812014-05-10 16:32:51 +0800168rem Note that there are no quotes as we do not want to introduce random
169rem quotes into the CLASSPATH
170if "%CLASSPATH%" == "" goto emptyClasspath
171set "CLASSPATH=%CLASSPATH%;"
172:emptyClasspath
刘洪青6266f992017-05-15 21:21:03 +0800173set "CLASSPATH=%CLASSPATH%%CATALINA_HOME%\bin\bootstrap.jar"
174
175if not "%CATALINA_TMPDIR%" == "" goto gotTmpdir
176set "CATALINA_TMPDIR=%CATALINA_BASE%\temp"
177:gotTmpdir
178
179rem Add tomcat-juli.jar to classpath
180rem tomcat-juli.jar can be over-ridden per instance
Hongqing Liufd5ee812014-05-10 16:32:51 +0800181if not exist "%CATALINA_BASE%\bin\tomcat-juli.jar" goto juliClasspathHome
刘洪青6266f992017-05-15 21:21:03 +0800182set "CLASSPATH=%CLASSPATH%;%CATALINA_BASE%\bin\tomcat-juli.jar"
Hongqing Liufd5ee812014-05-10 16:32:51 +0800183goto juliClasspathDone
184:juliClasspathHome
刘洪青6266f992017-05-15 21:21:03 +0800185set "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\bin\tomcat-juli.jar"
Hongqing Liufd5ee812014-05-10 16:32:51 +0800186:juliClasspathDone
187
刘洪青6266f992017-05-15 21:21:03 +0800188if not "%JSSE_OPTS%" == "" goto gotJsseOpts
189set JSSE_OPTS="-Djdk.tls.ephemeralDHKeySize=2048"
190:gotJsseOpts
191set "JAVA_OPTS=%JAVA_OPTS% %JSSE_OPTS%"
192
Hongqing Liufd5ee812014-05-10 16:32:51 +0800193if not "%LOGGING_CONFIG%" == "" goto noJuliConfig
194set LOGGING_CONFIG=-Dnop
195if not exist "%CATALINA_BASE%\conf\logging.properties" goto noJuliConfig
196set LOGGING_CONFIG=-Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties"
197:noJuliConfig
Hongqing Liufd5ee812014-05-10 16:32:51 +0800198
199if not "%LOGGING_MANAGER%" == "" goto noJuliManager
200set LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
201:noJuliManager
Hongqing Liufd5ee812014-05-10 16:32:51 +0800202
203rem ----- Execute The Requested Command ---------------------------------------
204
205echo Using CATALINA_BASE: "%CATALINA_BASE%"
206echo Using CATALINA_HOME: "%CATALINA_HOME%"
207echo Using CATALINA_TMPDIR: "%CATALINA_TMPDIR%"
208if ""%1"" == ""debug"" goto use_jdk
209echo Using JRE_HOME: "%JRE_HOME%"
210goto java_dir_displayed
211:use_jdk
212echo Using JAVA_HOME: "%JAVA_HOME%"
213:java_dir_displayed
214echo Using CLASSPATH: "%CLASSPATH%"
215
216set _EXECJAVA=%_RUNJAVA%
217set MAINCLASS=org.apache.catalina.startup.Bootstrap
218set ACTION=start
219set SECURITY_POLICY_FILE=
220set DEBUG_OPTS=
221set JPDA=
222
223if not ""%1"" == ""jpda"" goto noJpda
224set JPDA=jpda
225if not "%JPDA_TRANSPORT%" == "" goto gotJpdaTransport
226set JPDA_TRANSPORT=dt_socket
227:gotJpdaTransport
228if not "%JPDA_ADDRESS%" == "" goto gotJpdaAddress
229set JPDA_ADDRESS=8000
230:gotJpdaAddress
231if not "%JPDA_SUSPEND%" == "" goto gotJpdaSuspend
232set JPDA_SUSPEND=n
233:gotJpdaSuspend
234if not "%JPDA_OPTS%" == "" goto gotJpdaOpts
235set JPDA_OPTS=-agentlib:jdwp=transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
236:gotJpdaOpts
237shift
238:noJpda
239
240if ""%1"" == ""debug"" goto doDebug
241if ""%1"" == ""run"" goto doRun
242if ""%1"" == ""start"" goto doStart
243if ""%1"" == ""stop"" goto doStop
刘洪青6266f992017-05-15 21:21:03 +0800244if ""%1"" == ""configtest"" goto doConfigTest
Hongqing Liufd5ee812014-05-10 16:32:51 +0800245if ""%1"" == ""version"" goto doVersion
246
247echo Usage: catalina ( commands ... )
248echo commands:
249echo debug Start Catalina in a debugger
250echo debug -security Debug Catalina with a security manager
251echo jpda start Start Catalina under JPDA debugger
252echo run Start Catalina in the current window
253echo run -security Start in the current window with security manager
254echo start Start Catalina in a separate window
255echo start -security Start in a separate window with security manager
256echo stop Stop Catalina
刘洪青6266f992017-05-15 21:21:03 +0800257echo configtest Run a basic syntax check on server.xml
Hongqing Liufd5ee812014-05-10 16:32:51 +0800258echo version What version of tomcat are you running?
259goto end
260
261:doDebug
262shift
263set _EXECJAVA=%_RUNJDB%
264set DEBUG_OPTS=-sourcepath "%CATALINA_HOME%\..\..\java"
265if not ""%1"" == ""-security"" goto execCmd
266shift
267echo Using Security Manager
268set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"
269goto execCmd
270
271:doRun
272shift
273if not ""%1"" == ""-security"" goto execCmd
274shift
275echo Using Security Manager
276set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"
277goto execCmd
278
279:doStart
280shift
Hongqing Liufd5ee812014-05-10 16:32:51 +0800281if "%TITLE%" == "" set TITLE=Tomcat
282set _EXECJAVA=start "%TITLE%" %_RUNJAVA%
Hongqing Liufd5ee812014-05-10 16:32:51 +0800283if not ""%1"" == ""-security"" goto execCmd
284shift
285echo Using Security Manager
286set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"
287goto execCmd
288
289:doStop
290shift
291set ACTION=stop
292set CATALINA_OPTS=
293goto execCmd
294
刘洪青6266f992017-05-15 21:21:03 +0800295:doConfigTest
296shift
297set ACTION=configtest
298set CATALINA_OPTS=
299goto execCmd
300
Hongqing Liufd5ee812014-05-10 16:32:51 +0800301:doVersion
302%_EXECJAVA% -classpath "%CATALINA_HOME%\lib\catalina.jar" org.apache.catalina.util.ServerInfo
303goto end
304
305
306:execCmd
307rem Get remaining unshifted command line arguments and save them in the
308set CMD_LINE_ARGS=
309:setArgs
310if ""%1""=="""" goto doneSetArgs
311set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
312shift
313goto setArgs
314:doneSetArgs
315
316rem Execute Java with the applicable properties
317if not "%JPDA%" == "" goto doJpda
318if not "%SECURITY_POLICY_FILE%" == "" goto doSecurity
刘洪青6266f992017-05-15 21:21:03 +0800319%_EXECJAVA% %LOGGING_CONFIG% %LOGGING_MANAGER% %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%
Hongqing Liufd5ee812014-05-10 16:32:51 +0800320goto end
321:doSecurity
刘洪青6266f992017-05-15 21:21:03 +0800322%_EXECJAVA% %LOGGING_CONFIG% %LOGGING_MANAGER% %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%
Hongqing Liufd5ee812014-05-10 16:32:51 +0800323goto end
324:doJpda
325if not "%SECURITY_POLICY_FILE%" == "" goto doSecurityJpda
刘洪青6266f992017-05-15 21:21:03 +0800326%_EXECJAVA% %LOGGING_CONFIG% %LOGGING_MANAGER% %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%
Hongqing Liufd5ee812014-05-10 16:32:51 +0800327goto end
328:doSecurityJpda
刘洪青6266f992017-05-15 21:21:03 +0800329%_EXECJAVA% %LOGGING_CONFIG% %LOGGING_MANAGER% %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%
Hongqing Liufd5ee812014-05-10 16:32:51 +0800330goto end
331
332:end