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