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