Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
771 blopes 1
@echo off
2
rem Licensed to the Apache Software Foundation (ASF) under one or more
3
rem contributor license agreements.  See the NOTICE file distributed with
4
rem this work for additional information regarding copyright ownership.
5
rem The ASF licenses this file to You under the Apache License, Version 2.0
6
rem (the "License"); you may not use this file except in compliance with
7
rem the License.  You may obtain a copy of the License at
8
rem
9
rem     http://www.apache.org/licenses/LICENSE-2.0
10
rem
11
rem Unless required by applicable law or agreed to in writing, software
12
rem distributed under the License is distributed on an "AS IS" BASIS,
13
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
rem See the License for the specific language governing permissions and
15
rem limitations under the License.
16
 
17
rem ---------------------------------------------------------------------------
18
rem Start/Stop Script for the CATALINA Server
19
rem
20
rem For supported commands call "catalina.bat help" or see the usage section
21
rem towards the end of this file.
22
rem
23
rem Environment Variable Prerequisites
24
rem
25
rem   Do not set the variables in this script. Instead put them into a script
26
rem   setenv.bat in CATALINA_BASE/bin to keep your customizations separate.
27
rem
28
rem   WHEN RUNNING TOMCAT AS A WINDOWS SERVICE:
29
rem   Note that the environment variables that affect the behavior of this
30
rem   script will have no effect at all on Windows Services. As such, any
31
rem   local customizations made in a CATALINA_BASE/bin/setenv.bat script
32
rem   will also have no effect on Tomcat when launched as a Windows Service.
33
rem   The configuration that controls Windows Services is stored in the Windows
34
rem   Registry, and is most conveniently maintained using the "tomcat9w.exe"
35
rem   maintenance utility.
36
rem
37
rem   CATALINA_HOME   May point at your Catalina "build" directory.
38
rem
39
rem   CATALINA_BASE   (Optional) Base directory for resolving dynamic portions
40
rem                   of a Catalina installation.  If not present, resolves to
41
rem                   the same directory that CATALINA_HOME points to.
42
rem
43
rem   CATALINA_OPTS   (Optional) Java runtime options used when the "start",
44
rem                   "run" or "debug" command is executed.
45
rem                   Include here and not in JAVA_OPTS all options, that should
46
rem                   only be used by Tomcat itself, not by the stop process,
47
rem                   the version command etc.
48
rem                   Examples are heap size, GC logging, JMX ports etc.
49
rem
50
rem   CATALINA_TMPDIR (Optional) Directory path location of temporary directory
51
rem                   the JVM should use (java.io.tmpdir).  Defaults to
52
rem                   %CATALINA_BASE%\temp.
53
rem
54
rem   JAVA_HOME       Must point at your Java Development Kit installation.
55
rem                   Required to run the with the "debug" argument.
56
rem
57
rem   JRE_HOME        Must point at your Java Runtime installation.
58
rem                   Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME
59
rem                   are both set, JRE_HOME is used.
60
rem
61
rem   JAVA_OPTS       (Optional) Java runtime options used when any command
62
rem                   is executed.
63
rem                   Include here and not in CATALINA_OPTS all options, that
64
rem                   should be used by Tomcat and also by the stop process,
65
rem                   the version command etc.
66
rem                   Most options should go into CATALINA_OPTS.
67
rem
68
rem   JAVA_ENDORSED_DIRS (Optional) Lists of of semi-colon separated directories
69
rem                   containing some jars in order to allow replacement of APIs
70
rem                   created outside of the JCP (i.e. DOM and SAX from W3C).
71
rem                   It can also be used to update the XML parser implementation.
72
rem                   This is only supported for Java <= 8.
73
rem                   Defaults to $CATALINA_HOME/endorsed.
74
rem
75
rem   JPDA_TRANSPORT  (Optional) JPDA transport used when the "jpda start"
76
rem                   command is executed. The default is "dt_socket".
77
rem
78
rem   JPDA_ADDRESS    (Optional) Java runtime options used when the "jpda start"
79
rem                   command is executed. The default is localhost:8000.
80
rem
81
rem   JPDA_SUSPEND    (Optional) Java runtime options used when the "jpda start"
82
rem                   command is executed. Specifies whether JVM should suspend
83
rem                   execution immediately after startup. Default is "n".
84
rem
85
rem   JPDA_OPTS       (Optional) Java runtime options used when the "jpda start"
86
rem                   command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
87
rem                   and JPDA_SUSPEND are ignored. Thus, all required jpda
88
rem                   options MUST be specified. The default is:
89
rem
90
rem                   -agentlib:jdwp=transport=%JPDA_TRANSPORT%,
91
rem                       address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
92
rem
93
rem   JSSE_OPTS       (Optional) Java runtime options used to control the TLS
94
rem                   implementation when JSSE is used. Default is:
95
rem                   "-Djdk.tls.ephemeralDHKeySize=2048"
96
rem
97
rem   CATALINA_LOGGING_CONFIG (Optional) Override Tomcat's logging config file
98
rem                   Example (all one line)
99
rem                   set CATALINA_LOGGING_CONFIG=-Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties"
100
rem
101
rem   LOGGING_CONFIG  Deprecated
102
rem                   Use CATALINA_LOGGING_CONFIG
103
rem                   This is only used if CATALINA_LOGGING_CONFIG is not set
104
rem                   and LOGGING_CONFIG starts with "-D..."
105
rem
106
rem   LOGGING_MANAGER (Optional) Override Tomcat's logging manager
107
rem                   Example (all one line)
108
rem                   set LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
109
rem
110
rem   TITLE           (Optional) Specify the title of Tomcat window. The default
111
rem                   TITLE is Tomcat if it's not specified.
112
rem                   Example (all one line)
113
rem                   set TITLE=Tomcat.Cluster#1.Server#1 [%DATE% %TIME%]
114
rem ---------------------------------------------------------------------------
115
 
116
setlocal
117
 
118
rem Suppress Terminate batch job on CTRL+C
119
if not ""%1"" == ""run"" goto mainEntry
120
if "%TEMP%" == "" goto mainEntry
121
if exist "%TEMP%\%~nx0.run" goto mainEntry
122
echo Y>"%TEMP%\%~nx0.run"
123
if not exist "%TEMP%\%~nx0.run" goto mainEntry
124
echo Y>"%TEMP%\%~nx0.Y"
125
call "%~f0" %* <"%TEMP%\%~nx0.Y"
126
rem Use provided errorlevel
127
set RETVAL=%ERRORLEVEL%
128
del /Q "%TEMP%\%~nx0.Y" >NUL 2>&1
129
exit /B %RETVAL%
130
:mainEntry
131
del /Q "%TEMP%\%~nx0.run" >NUL 2>&1
132
 
133
rem Guess CATALINA_HOME if not defined
134
set "CURRENT_DIR=%cd%"
135
if not "%CATALINA_HOME%" == "" goto gotHome
136
set "CATALINA_HOME=%CURRENT_DIR%"
137
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
138
cd ..
139
set "CATALINA_HOME=%cd%"
140
cd "%CURRENT_DIR%"
141
:gotHome
142
 
143
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
144
echo The CATALINA_HOME environment variable is not defined correctly
145
echo This environment variable is needed to run this program
146
goto end
147
:okHome
148
 
149
rem Copy CATALINA_BASE from CATALINA_HOME if not defined
150
if not "%CATALINA_BASE%" == "" goto gotBase
151
set "CATALINA_BASE=%CATALINA_HOME%"
152
:gotBase
153
 
154
rem Ensure that neither CATALINA_HOME nor CATALINA_BASE contains a semi-colon
155
rem as this is used as the separator in the classpath and Java provides no
156
rem mechanism for escaping if the same character appears in the path. Check this
157
rem by replacing all occurrences of ';' with '' and checking that neither
158
rem CATALINA_HOME nor CATALINA_BASE have changed
159
if "%CATALINA_HOME%" == "%!!%" goto homeNoSemicolon
160
echo Using CATALINA_HOME:   "%CATALINA_HOME%"
161
echo Unable to start as CATALINA_HOME contains a semicolon (;) character
162
goto end
163
:homeNoSemicolon
164
 
165
if "%CATALINA_BASE%" == "%!!%" goto baseNoSemicolon
166
echo Using CATALINA_BASE:   "%CATALINA_BASE%"
167
echo Unable to start as CATALINA_BASE contains a semicolon (;) character
168
goto end
169
:baseNoSemicolon
170
 
171
rem Ensure that any user defined CLASSPATH variables are not used on startup,
172
rem but allow them to be specified in setenv.bat, in rare case when it is needed.
173
set CLASSPATH=
174
 
175
rem Get standard environment variables
176
if not exist "%CATALINA_BASE%\bin\setenv.bat" goto checkSetenvHome
177
call "%CATALINA_BASE%\bin\setenv.bat"
178
goto setenvDone
179
:checkSetenvHome
180
if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat"
181
:setenvDone
182
 
183
rem Get standard Java environment variables
184
if exist "%CATALINA_HOME%\bin\setclasspath.bat" goto okSetclasspath
185
echo Cannot find "%CATALINA_HOME%\bin\setclasspath.bat"
186
echo This file is needed to run this program
187
goto end
188
:okSetclasspath
189
call "%CATALINA_HOME%\bin\setclasspath.bat" %1
190
if errorlevel 1 goto end
191
 
192
rem Add on extra jar file to CLASSPATH
193
rem Note that there are no quotes as we do not want to introduce random
194
rem quotes into the CLASSPATH
195
if "%CLASSPATH%" == "" goto emptyClasspath
196
set "CLASSPATH=%CLASSPATH%;"
197
:emptyClasspath
198
set "CLASSPATH=%CLASSPATH%%CATALINA_HOME%\bin\bootstrap.jar"
199
 
200
if not "%CATALINA_TMPDIR%" == "" goto gotTmpdir
201
set "CATALINA_TMPDIR=%CATALINA_BASE%\temp"
202
:gotTmpdir
203
 
204
rem Add tomcat-juli.jar to classpath
205
rem tomcat-juli.jar can be over-ridden per instance
206
if not exist "%CATALINA_BASE%\bin\tomcat-juli.jar" goto juliClasspathHome
207
set "CLASSPATH=%CLASSPATH%;%CATALINA_BASE%\bin\tomcat-juli.jar"
208
goto juliClasspathDone
209
:juliClasspathHome
210
set "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\bin\tomcat-juli.jar"
211
:juliClasspathDone
212
 
213
if not "%JSSE_OPTS%" == "" goto gotJsseOpts
214
set "JSSE_OPTS=-Djdk.tls.ephemeralDHKeySize=2048"
215
:gotJsseOpts
216
set "JAVA_OPTS=%JAVA_OPTS% %JSSE_OPTS%"
217
 
218
rem Register custom URL handlers
219
rem Do this here so custom URL handles (specifically 'war:...') can be used in the security policy
220
set "JAVA_OPTS=%JAVA_OPTS% -Djava.protocol.handler.pkgs=org.apache.catalina.webresources"
221
 
222
rem Disable the global canonical file name cache to protect against CVE-2024-56337
223
rem Note: The cache is disabled by default in Java 12 to 20 inclusive
224
rem       The cache is removed in Java 21 onwards
225
rem Need to set this here as java.io.FileSystem caches this in a static field during class
226
rem initialisation so it needs to be set before any file system access
227
set "JAVA_OPTS=%JAVA_OPTS% -Dsun.io.useCanonCaches=false"
228
 
229
rem Check for the deprecated LOGGING_CONFIG
230
rem Only use it if CATALINA_LOGGING_CONFIG is not set and LOGGING_CONFIG starts with "-D..."
231
if not "%LOGGING_CONFIG:~0,2%"=="-D" goto noLoggingDeprecation
232
if not "%CATALINA_LOGGING_CONFIG%" == "" goto noLoggingDeprecation
233
set "CATALINA_LOGGING_CONFIG=%LOGGING_CONFIG%"
234
:noLoggingDeprecation
235
 
236
if not "%CATALINA_LOGGING_CONFIG%" == "" goto noJuliConfig
237
set CATALINA_LOGGING_CONFIG=-Dnop
238
if not exist "%CATALINA_BASE%\conf\logging.properties" goto noJuliConfig
239
set CATALINA_LOGGING_CONFIG=-Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties"
240
:noJuliConfig
241
 
242
if not "%LOGGING_MANAGER%" == "" goto noJuliManager
243
set LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
244
:noJuliManager
245
 
246
rem Configure JAVA 9 specific start-up parameters - ensure to keep it in line with service.bat
247
set "JDK_JAVA_OPTIONS=%JDK_JAVA_OPTIONS% --add-opens=java.base/java.lang=ALL-UNNAMED"
248
set "JDK_JAVA_OPTIONS=%JDK_JAVA_OPTIONS% --add-opens=java.base/java.lang.invoke=ALL-UNNAMED"
249
set "JDK_JAVA_OPTIONS=%JDK_JAVA_OPTIONS% --add-opens=java.base/java.lang.reflect=ALL-UNNAMED"
250
set "JDK_JAVA_OPTIONS=%JDK_JAVA_OPTIONS% --add-opens=java.base/java.io=ALL-UNNAMED"
251
set "JDK_JAVA_OPTIONS=%JDK_JAVA_OPTIONS% --add-opens=java.base/java.util=ALL-UNNAMED"
252
set "JDK_JAVA_OPTIONS=%JDK_JAVA_OPTIONS% --add-opens=java.base/java.util.concurrent=ALL-UNNAMED"
253
set "JDK_JAVA_OPTIONS=%JDK_JAVA_OPTIONS% --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED"
254
 
255
rem Java 9 no longer supports the java.endorsed.dirs
256
rem system property. Only try to use it if
257
rem JAVA_ENDORSED_DIRS was explicitly set
258
rem or CATALINA_HOME/endorsed exists.
259
set ENDORSED_PROP=ignore.endorsed.dirs
260
if "%JAVA_ENDORSED_DIRS%" == "" goto noEndorsedVar
261
set ENDORSED_PROP=java.endorsed.dirs
262
goto doneEndorsed
263
:noEndorsedVar
264
if not exist "%CATALINA_HOME%\endorsed" goto doneEndorsed
265
set ENDORSED_PROP=java.endorsed.dirs
266
:doneEndorsed
267
 
268
rem ----- Execute The Requested Command ---------------------------------------
269
 
270
echo Using CATALINA_BASE:   "%CATALINA_BASE%"
271
echo Using CATALINA_HOME:   "%CATALINA_HOME%"
272
echo Using CATALINA_TMPDIR: "%CATALINA_TMPDIR%"
273
if ""%1"" == ""debug"" goto use_jdk
274
echo Using JRE_HOME:        "%JRE_HOME%"
275
goto java_dir_displayed
276
:use_jdk
277
echo Using JAVA_HOME:       "%JAVA_HOME%"
278
:java_dir_displayed
279
echo Using CLASSPATH:       "%CLASSPATH%"
280
echo Using CATALINA_OPTS:   "%CATALINA_OPTS%"
281
 
282
set _EXECJAVA="%_RUNJAVA%"
283
set MAINCLASS=org.apache.catalina.startup.Bootstrap
284
set ACTION=start
285
set SECURITY_POLICY_FILE=
286
set DEBUG_OPTS=
287
set JPDA=
288
 
289
if not ""%1"" == ""jpda"" goto noJpda
290
set JPDA=jpda
291
if not "%JPDA_TRANSPORT%" == "" goto gotJpdaTransport
292
set JPDA_TRANSPORT=dt_socket
293
:gotJpdaTransport
294
if not "%JPDA_ADDRESS%" == "" goto gotJpdaAddress
295
set JPDA_ADDRESS=localhost:8000
296
:gotJpdaAddress
297
if not "%JPDA_SUSPEND%" == "" goto gotJpdaSuspend
298
set JPDA_SUSPEND=n
299
:gotJpdaSuspend
300
if not "%JPDA_OPTS%" == "" goto gotJpdaOpts
301
set JPDA_OPTS=-agentlib:jdwp=transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
302
:gotJpdaOpts
303
shift
304
:noJpda
305
 
306
if ""%1"" == ""debug"" goto doDebug
307
if ""%1"" == ""run"" goto doRun
308
if ""%1"" == ""start"" goto doStart
309
if ""%1"" == ""stop"" goto doStop
310
if ""%1"" == ""configtest"" goto doConfigTest
311
if ""%1"" == ""version"" goto doVersion
312
 
313
echo Usage:  catalina ( commands ... )
314
echo commands:
315
echo   debug             Start Catalina in a debugger
316
echo   debug -security   Debug Catalina with a security manager
317
echo   jpda start        Start Catalina under JPDA debugger
318
echo   run               Start Catalina in the current window
319
echo   run -security     Start in the current window with security manager
320
echo   start             Start Catalina in a separate window
321
echo   start -security   Start in a separate window with security manager
322
echo   stop              Stop Catalina
323
echo   configtest        Run a basic syntax check on server.xml
324
echo   version           What version of tomcat are you running?
325
goto end
326
 
327
:doDebug
328
shift
329
set _EXECJAVA="%_RUNJDB%"
330
set DEBUG_OPTS=-sourcepath "%CATALINA_HOME%\..\..\java"
331
if not ""%1"" == ""-security"" goto execCmd
332
shift
333
echo Using Security Manager
334
set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"
335
goto execCmd
336
 
337
:doRun
338
shift
339
if not ""%1"" == ""-security"" goto execCmd
340
shift
341
echo Using Security Manager
342
set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"
343
goto execCmd
344
 
345
:doStart
346
shift
347
if "%TITLE%" == "" set TITLE=Tomcat
348
set _EXECJAVA=start "%TITLE%" "%_RUNJAVA%"
349
if not ""%1"" == ""-security"" goto execCmd
350
shift
351
echo Using Security Manager
352
set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"
353
goto execCmd
354
 
355
:doStop
356
shift
357
set ACTION=stop
358
set CATALINA_OPTS=
359
goto execCmd
360
 
361
:doConfigTest
362
shift
363
set ACTION=configtest
364
set CATALINA_OPTS=
365
goto execCmd
366
 
367
:doVersion
368
%_EXECJAVA% %JAVA_OPTS% -classpath "%CATALINA_HOME%\lib\catalina.jar" org.apache.catalina.util.ServerInfo
369
goto end
370
 
371
 
372
:execCmd
373
rem Get remaining unshifted command line arguments and save them in the
374
set CMD_LINE_ARGS=
375
:setArgs
376
if ""%1""=="""" goto doneSetArgs
377
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
378
shift
379
goto setArgs
380
:doneSetArgs
381
 
382
rem Execute Java with the applicable properties
383
if not "%JPDA%" == "" goto doJpda
384
if not "%SECURITY_POLICY_FILE%" == "" goto doSecurity
385
%_EXECJAVA% %CATALINA_LOGGING_CONFIG% %LOGGING_MANAGER% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -D%ENDORSED_PROP%="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
386
goto end
387
:doSecurity
388
%_EXECJAVA% %CATALINA_LOGGING_CONFIG% %LOGGING_MANAGER% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -D%ENDORSED_PROP%="%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%
389
goto end
390
:doJpda
391
if not "%SECURITY_POLICY_FILE%" == "" goto doSecurityJpda
392
%_EXECJAVA% %CATALINA_LOGGING_CONFIG% %LOGGING_MANAGER% %JAVA_OPTS% %JPDA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -D%ENDORSED_PROP%="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
393
goto end
394
:doSecurityJpda
395
%_EXECJAVA% %CATALINA_LOGGING_CONFIG% %LOGGING_MANAGER% %JAVA_OPTS% %JPDA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -D%ENDORSED_PROP%="%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%
396
goto end
397
 
398
:end