Tomcat starts batch processing -- Catalina. bat

Source: Internet
Author: User
Tags configuration settings


This batch processing is the core script for Tomcat server startup and shutdown. Including .... (Various variables). This section describes the logic of this batch.
First look at the first part of the script:
**************************************** **************************************** ************
If not "" % 1 "" = "" Run "" Goto mainentry
If "% Temp %" = "" Goto mainentry
If exist "% Temp % \ % ~ Nx0.run "Goto mainentry
Echo y> "% Temp % \ % ~ Nx0.run"
If not exist "% Temp % \ % ~ Nx0.run "Goto mainentry
Echo y> "% Temp % \ % ~ Nx0.y"
Call "% ~ F0 "% * <" % Temp % \ % ~ Nx0.y"
Set retval = % errorlevel %
Del/Q "% Temp % \ % ~ Nx0.y "> NUL 2> & 1
Exit/B % retval %
: Mainentry
Del/Q "% Temp % \ % ~ Nx0.run "> NUL 2> & 1
**************************************** **************************************** ************
The first line determines that if % 1 means that the first parameter is equal to run, it will jump directly to mainentry. Two double quotation marks are used to prevent the parameter from carrying spaces; in the second row, if the TEMP environment variable is null, the system will jump to mainentry. In the third row, the system will determine whether Catalina exists in the TEMP environment variable directory. BAT. the run file jumps directly to mainentry. The fourth line inputs the letter y into Catalina. BAT. run file; the fifth line determines if Catalina does not exist. BAT. the run file jumps to mainentry. The sixth line will contain the letter y, which is entered into Catalina. BAT. in the y file; the seventh line is Catalina. BAT. Y is used as the input to execute the current batch processing. % * indicates all parameters. Row 8 assigns the % errorlevel % variable after execution to retval. If the execution process encounters a problem, the value is non-zero; row 9 deletes Catalina. BAT. Y file, and the execution result is not output. In addition, stderr is redirected to stdout. Row 10 exits the current batch processing script. And use the retval variable as the return value. The remaining two lines of script are not described in detail.
The second part of the script mainly sets catalina_home and catalina_base variables.
**************************************** **************************************** ************
Set "current_dir = % Cd %"
If not "% catalina_home %" = "" Goto gothome
Set "catalina_home = % current_dir %"
If exist "% catalina_home % \ bin \ Catalina. Bat" Goto okhome
CD ..
Set "catalina_home = % Cd %"
Cd "% current_dir %"
: Gothome
If exist "% catalina_home % \ bin \ Catalina. Bat" Goto okhome
Goto end
: Okhome
If not "% catalina_base %" = "" Goto gotbase
Set "catalina_base = % catalina_home %"
: Gotbase
**************************************** **************************************** ************
Set the catalina_home environment variable. The logic is the same as that of startup. bat. Why do we need to set the catalina_home environment variable? To put it simply, you can run Catalina. Bat directly instead of using startup. bat. Set the catalina_base environment variable. Here, the value of catalina_home is directly assigned to it.
The third part of the script is to set the classpath environment variables and add various jar packages to the classpath.
**************************************** **************************************** ************
Set classpath =
If not exist "% catalina_base % \ bin \ setenv. Bat" Goto checksetenvhome
Call "% catalina_base % \ bin \ setenv. Bat"
Goto setenvdone
: Checksetenvhome
If exist "% catalina_home % \ bin \ setenv. Bat" call "% catalina_home % \ bin \ setenv. Bat"
: Setenvdone
If exist "% catalina_home % \ bin \ setclasspath. Bat" Goto oksetclasspath
Goto end
: Oksetclasspath
Call "% catalina_home % \ bin \ setclasspath. Bat" % 1
If errorlevel 1 goto end
If "% classpath %" = "" Goto emptyclasspath
Set "classpath = % classpath % ;"
: Emptyclasspath
Set "classpath = % classpath % catalina_home % \ bin \ Bootstrap. Jar"
If not "% catalina_tmpdir %" = "" Goto gottmpdir
Set "catalina_tmpdir = % catalina_base % \ Temp"
: Gottmpdir
If not exist "% catalina_base % \ bin \ tomcat-juli.jar" Goto juliclasspathhome
Set "classpath = % classpath %; % catalina_base % \ bin \ tomcat-juli.jar"
Goto juliclasspathdone
: Juliclasspathhome
Set "classpath = % classpath %; % catalina_home % \ bin \ tomcat-juli.jar"
: Juliclasspathdone
**************************************** **************************************** ************
Set classpath to null to check whether setenv exists in the % catalina_base % \ bin directory. bat. If yes, call this batch of files. Otherwise, check whether setenv exists in the % catalina_home % \ bin directory. bat. Execute the command if it exists. Continue to determine whether % catalina_home % \ bin \ setclasspath exists. BAT file. If it does not exist, it will jump to the end, indicating the setclasspath. bat is a necessary batch processing script and then runs setclasspath. bat script. % 1 indicates the parameter. If errorlevel 1 goto end indicates to execute this command. If the error value is greater than or equal to 1, it will jump directly to the end. If there is no error, continue to the next step and check whether the environment variable % classpath % is null, if it is not null, set classpath to % classpath % with a semicolon. Then, set % catalina_home % \ bin \ Bootstrap. jar is added to classpath. This package is the Tomcat kernel. Then set the temporary directory temp, append the tomcat-juli.jar package to classpath, the basic logic is to first find from the % catalina_base % \ bin directory, if it does not exist, then go to the % catalina_home % \ bin directory to find. Tomcat-juli.jar this package mainly contains Tomcat System Log processing class, please review the third part of the fourth section-log framework for details.
The fourth part is the log configuration settings.
**************************************** **************************************** ************
If not "% logging_config %" = "" Goto nojuliconfig
Set logging_config =-dnop
If not exist "% catalina_base % \ conf \ Logging. properties" Goto nojuliconfig
Set logging_config =-djava. util. Logging. config. File = "% catalina_base % \ conf \ Logging. properties"
: Nojuliconfig
Set java_opts = % java_opts % logging_config %
If not "% logging_manager %" = "" Goto nojulimanager
Set logging_manager =-djava. util. Logging. Manager = org. Apache. Juli. classloaderlogmanager
: Nojulimanager
Set java_opts = % java_opts % logging_manager %
**************************************** **************************************** ************
The log implementation in Tomcat uses the log tool class that comes with JDK. The main two attributes can be configured, namely Java. util. logging. config. file and Java. util. logging. MANAGER: first, determine whether the environment variable has logging_config and use it directly if it exists. Otherwise, set logging_config to-dnop and determine whether % catalina_base % \ conf \ Logging exists. properties. If yes, logging_config is set to-djava. util. logging. config. file = "% catalina_base % \ conf \ Logging. properties ". Note: Set java_opts = % java_opts % logging_config %. You will find that there is no java_opts variable or java_opts environment variable in front of the original version, the purpose of this operation is to append all parameters to java_opts. For example, if the O & M personnel already have the java_opts variable, it will be appended to java_opts after execution, if no java_opts variable exists, it is used as a null value and does not affect the operation. The setting of the logging_manager variable is the same as that of logging_config.
The fifth part is the initialization of some parameters before the command is executed.
**************************************** **************************************** ************
Set _ execjava = % _ runjava %
Set mainclass = org. Apache. Catalina. startup. Bootstrap
Set action = start
Set security_policy_file =
Set debug_opts =
Set JPDA =
If not "" % 1 "" = "" JPDA "" Goto nojpda
Set JPDA = JPDA
If not "% jpda_transport %" = "" Goto gotjpdatransport
Set jpda_transport = dt_socket
: Gotjpdatransport
If not "% jpda_address %" = "" Goto gotjpdaaddress
Set jpda_address = 8000
: Gotjpdaaddress
If not "% jpda_suspend %" = "" Goto gotjpdasuspend
Set jpda_suspend = N
: Gotjpdasuspend
If not "% jpda_opts %" = "" Goto gotjpdaopts
Set jpda_opts =-agentlib: jdwp = transport = % jpda_transport %, address = % jpda_address %, Server = Y, suspend = % jpda_suspend %
: Gotjpdaopts
Shift
: Nojpda
**************************************** **************************************** ************
Assign % _ runjava % variable to _ execjava, and % _ runjava % variable to setclasspath. the bat script has been set to % jre_home % \ bin \ Java, set mainclass to Tomcat's startup class Bootstrap, action to start, and other variables are not initialized first. If the first parameter is JPDA, set the JPDA variable as the value JPDA. JPDA is the Java platform debugging architecture, which provides convenient remote debugging; if the jpda_transport variable is null, it is set to dt_socket; if the jpda_address variable is null, it is set to 8000; if the jpda_suspend variable is null, it is set to N; if the jpda_opts variable is null, set it to-agentlib: jdwp = transport = % jpda_transport %, address = % jpda_address %, Server = Y, suspend = % jpda_suspend %. Finally, a shift is used to move the parameter one by one. This section mainly initializes the JPDA startup command item and loads the jdwp proxy to the JVM of the application.
The sixth part of the command is to jump to different locations to execute different commands based on different parameters. In fact, it is also to assemble some parameters to prepare for the next step.
**************************************** **************************************** ************
If "% 1" "=" "debug" "Goto dodebug
If "% 1" "=" "Run" "Goto dorun
If "% 1" "=" "start" "Goto dostart
If "% 1" "=" "Stop" "Goto dostop
If "% 1" "=" "configtest" "Goto doconfigtest
If "% 1" "=" "version" "Goto doversion
: Dodebug
Shift
Set _ execjava = % _ runjdb %
Set debug_opts =-sourcepath "% catalina_home % \... \ Java"
If not "" % 1 "" = ""-Security "" Goto execcmd
Shift
Set "security_policy_file = % catalina_base % \ conf \ Catalina. Policy"
Goto execcmd
: Dorun
Shift
If not "" % 1 "" = ""-Security "" Goto execcmd
Shift
Set "security_policy_file = % catalina_base % \ conf \ Catalina. Policy"
Goto execcmd
: Dostart
Shift
If not "% OS %" = "windows_nt" Goto notitle
If "% title %" = "" set Title = Tomcat
Set _ execjava = start "% title %" % _ runjava %
Goto gottitle
: Notitle
Set _ execjava = start % _ runjava %
: Gottitle
If not "" % 1 "" = ""-Security "" Goto execcmd
Shift
Set "security_policy_file = % catalina_base % \ conf \ Catalina. Policy"
Goto execcmd
: Dostop
Shift
Set action = stop
Set catalina_opts =
Goto execcmd
: Doconfigtest
Shift
Set action = configtest
Set catalina_opts =
Goto execcmd
: Doversion
% _ Execjava %-classpath "% catalina_home % \ Lib \ Catalina. Jar" org. Apache. Catalina. util. serverinfo
Goto end
**************************************** **************************************** ************
Previously, shift was used to move the parameter one by one. At this time, the parameter represented by % 1 is already the next parameter, perform different operations according to debug, run, start, stop, configtest, and version to the dodebug, dorun, dostart, dostop, doconfigtest, and doversion labels. The following six operations are analyzed:
The logic of dodebug is to move the parameter one by one and set the _ execjava variable to % _ runjdb %, the _ runjdb variable has been set to % java_home % \ bin \ jdb in the setclasspath batch processing script, set the debug_opts variable, and then determine whether the parameter is equal to-security, that is, whether to start the security manager, if not, directly jump to the execcmd position. Otherwise, the parameter is moved one byte and the security_policy_file variable is set to % catalina_base % \ conf \ Catalina. policy, This Catalina. for more information about the role of policy, see Section 4 security framework. Finally, jump to the execcmd position.
The logic of dorun is to move the parameter one byte to determine whether the security manager is used. If the security manager is not used, it will jump directly to the execcmd position. Otherwise, the parameter will be moved one byte and the security_policy_file variable will be set, finally, jump to the execcmd position.
The logic of dostart is to move the parameter one by one. The title of the command window is set according to whether the system is windows _ nt, and the title variable is set as a tomcat string. Set the _ execjava variable. If there is a title, add it to the startup command, then determine whether to use the security manager, move the parameter one by one, set security_policy_file, and finally jump to the execcmd position.
The logic of dostop and doconfigtest is similar. You can move the parameters one by one, set the action variable to stop and configtest, clear the catalina_opts variable, and jump to the execcmd position.
Doversion is actually to display the server information. You can directly call the java.exe program under the % jre_home % \ bin directory, % catalina_home % \ Lib \ Catalina. jar as classpath, org. apache. catalina. util. serverinfo is used as the startup class to output server-related information and end the command.
Part 7: command execution.
**************************************** **************************************** ************
: Execcmd
Set pai_line_args =
: Setargs
If "% 1" "=" Goto donesetargs
Set cmd_line_args = % cmd_line_args % 1
Shift
Goto setargs
: Donesetargs
If not "% JPDA %" = "" Goto dojpda
If not "% security_policy_file %" = "" Goto dosecurity
% _ 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 %
Goto end
: Dosecurity
% _ 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 %
Goto end
: Dojpda
If not "% security_policy_file %" = "" Goto dosecurityjpda
% _ 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 %
Goto end
: Dosecurityjpda
% _ 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 %
Goto end
: End
**************************************** **************************************** ************
The first step is to collect the parameters, which have been seen before and will not be described here. The next step is to execute different commands Based on the parameter values, and use a diagram to describe the logic in it more clearly. 3-2-1-2. It mainly uses the JPDA and security_policy_file variables to determine whether to use the Java platform to debug the architecture and security manager. In this way, four different commands can be formed. Let's look at the details of the most comprehensive commands:

Figure 3-2-1-2
If you use both the security manager and the Java platform debugging system to start the service, the system will jump to the dosecurityjpda location.
% _ Execjava %: Start "Tomcat" "D: \ Java \ JDK \ bin \ Java" (assuming the Java installation path is D: \ Java \ JDK ).
% Java_opts %:-djava. util. logging. config. file = "D: \ Java \ apache-Tomcat-7.0.39 \ conf \ Logging. properties "-djava. util. logging. manager = org. apache. juli. classloaderlogmanager.
% Catalina_opts %: null.
% Jpda_opts %:-agentlib: jdwp = transport = dt_socket, address = 8000, Server = Y, suspend = n.
% Debug_opts %: null.
% Java_endorsed_dirs %: "D: \ apache-Tomcat \ endorsed" (assume that the tomcat installation directory is D: \ apache-Tomcat ).
% Classpath % is: "D: \ apache-Tomcat \ bin \ Bootstrap. jar; D: \ apache-Tomcat \ bin \ tomcat-juli.jar ".
% Security_policy_file % is: D: \ apache-Tomcat \ conf \ Catalina. Policy.
% Catalina_base % is: D: \ apache-Tomcat.
% Catalina_home % is: D: \ apache-Tomcat.
% Catalina_tmpdir % is: D: \ apache-Tomcat \ temp.
% Mainclass % is org. Apache. Catalina. startup. Bootstrap.
% Cmd_line_args %: null.
% Action % is: start.
Assemble the preceding variable values into a command line that is the final STARTUP script.

Tomcat starts batch processing -- Catalina. bat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.