Tomcat starts script catalina.sh

zhaozj2021-02-16  160

1 Overview

Script Catalina.sh is used to launch and close Tomcat servers. It is the most critical script. Additional scripts Startup.sh and shutdown.sh are all calling the script using different parameters This script is as follows (from this script itself) :

echo "Usage: Catalina.sh (Commands ...)

echo "Commands:"

Echo "Debug Start Catalina In A Debugger"

Echo "Debug-Security Debug Catalina with a security manager"

Echo "Embedded Start Catalina in Embedded Mode"

Echo "JPDA Start Start Catalina Under JPDA Debugger"

Echo "Run Start Catalina In The Current WinDow"

Echo "Run -security Start In The Current Window with Security Manager"

Echo "Start Start Catalina in a Separate Window"

Echo "Start-Security Start in a Separate Window with security manager"

Echo "Stop Stop Catalina"

2 - scripting analysis

#! / bin / sh

# ===================================================== ============

# This script sets the correct environment variable and system information, then start or stop Tomcat Server

# The specific operation is:

# Use the command line parameter as the args of Args, call org.apache.catalina.startup.bootstrap.main (String [])

# ===================================================== =============

# ------------------------------------------------- ----------------------------

# Start / stop Script for the catalina server #

# Environment Variable Prequisites

#

# Catalina_Home May Point at your Catalina "Build" Directory.

#

# Catalina_Base (optional) Base Directory for Resolving Dynamic Portions

# of a catalina installation. if not present, resolves to

# The Same Directory That Catalina_Home Points T.

#

# Catalina_opts (optional) Java Runtime Options Used when "Start",

# "stop", or "run" Command is Executed.

#

# Catalina_TMPDir (Optional) Directory Path location of Temporary DIRECTORY

# The JVM Should Use (java.io.tmpdir). Defaults to

# $ Catalina_base / temp.

#

# Java_Home Must Point At Your Java Development Kit Installation.

#

# Java_opts (optional) Java Runtime Options Used when "start",

# "stop", or "run" Command is Executed.

#

# JPDA_TRANSPORT (OPTIONAL) JPDA TRANSPORT USED WHEN THE "JPDA START"

# Command is executed. The default is "dt_socket".

#

# JPDA_ADDRESS (OPTIONAL) Java Runtime Options Used when "JPDA START"

# Command IS EXECUTED. The default is 8000.

#

# Jsse_home (optional) May Point At Your Java Secure Sockets Extension

# (Jsse) Installation, Whose Jar Files Will Be Added to the THE

# System class path used to start tomcat.

#

# Catalina_pid (optional) Path of the file Which should Contains the PID

# of catalina Startup Java Process, When Start (fork) IS Used

# ------------------------------------------------- ---------------------------- # os specific support. $ Var _must_ be set to each of the estuary.

Cygwin = false

Case "` uname` "in

Cygwin *) cygwin = true ;;

ESAC

# PRG is the name of the script being executed, which can be considered PRG == "Catalina.sh", or a symbolic chain, pointing to this script.

PRG = "$ 0"

# Handling the PRG, etc. After the cycle is jumped out, the PRG becomes ????

While [-h "$ prop"]; do

Ls = `ls -ld" $ prag "`

Link = `EXPR" $ ls ": '. * -> /(.*/) $'`

If EXPR "$ link": '. * /. *'> / dev / null; then

PRG = "$ link"

Else

PRG = `Dirname" $ ​​PRG "` / "$ limited"

Fi

DONE

# Prgdir is the directory path name of the PRG

Prgdir = `Dirname" $ ​​prag "`

# Execute $ CATALINA_HOME / BIN / STENV.SH to set the environment variable

# [-r filename] is to determine if the file exists and readable

Catalina_home = `CD" $ prgdir / .. "; pwd`

IF [-r "$ CATALINA_HOME" /bin/setenv.sh]; then

"$ CATALINA_HOME" /bin/setenv.sh

Fi

# For cygwin, make sure all pathnames are in accordance with UNIX format

IF $ cygwin; then

[-n "$ java_home"] && java_home = `Cygpath --unix" $ java_home "`

[-n "$ catalina_home"] && catalina_home = `Cygpath --unix" $ catalina_home "`

[-n "$ catalina_base"] && catalina_base = `Cygpath --unix" $ catalina_base "`

[-n "$ classpath"] && classpath = `Cygpath --Path --unix" $ classpath "`

[-n "$ jsse_home"] && jsse_home = `cygpath --path --unix" $ jsse_home "`

Fi

# Set the classpath variable used to initialize SystemClassLoader: Complete by executing script setClassPath.sh

# Note: Script setClassPath.sh changed the original $ ClassPath variable, and set it to:

# ClassPath = $ catalina_home / bin / bootstrap.jar: $ java_home / lib / Tools.jar # where bootstrap.jar is package document,

# Contains the startup method org.apache.catalina.startup.bootstrap.main (String [] args

# Tools.jar contains a Javac compiler to compile JSP files into servlet class.

IF [-r "$ CATALINA_HOME" /bin/setclasspath.sh]; then

Basedir = "$ CATALINA_HOME"

"$ CATALINA_HOME" /bin/setclasspath.sh

Else

Echo "Cannot Find $ Catalina_Home / Bin / SetClassPath.sh"

Echo "this file is neededed to run this program"

EXIT 1

Fi

# 补 some JAR files after the ClassPath environment variable

# [-n string] Judging whether the string is not 0; [-z string] Judging whether the string is 0

# They can be used to determine if an environment variable has been set

IF [-n "$ jsse_home"]; then

ClassPath = "$ ClassPath": "$ jsse_home" /lib/jcert.jar: "$ jsse_home" /lib/jnet.jar: "$ jsse_home" /lib/jsse.jar

Fi

Classpath = "$ ClassPath": "$ catalina_home" /bin/bootstrap.jar

# Specify Catalina_Base variables

# If catalina_base doesn't have a value, let Catalina_Base = $ CATALINA_HOME

IF [-z "$ CATALINA_BASE"]; then

Catalina_base = "$ CATALINA_HOME"

Fi

# Specify Catalina_TMPDIR variables

# If Catalina_TMPDIR does not value, let Catalina_TMPDIR = $ CATALINA_BASE / TEMP

IF [-z "$ Catalina_TMPDir"]; then

# Define the java.io.tmpdir to use for catalina

Catalina_tmpdir = "$ catalina_base" / TEMP

Fi

# For cygwin, convert the path name into a Windows format before executing the Java program

IF $ cygwin; then

Java_Home = `Cygpath --Path - Windows" $ java_home "`

Catalina_home = `Cygpath --Path - Windows" $ CATALINA_HOME "`

Catalina_base = `cygpath --Path - Windows" $ CATALINA_BASE "`

Catalina_tmpdir = `Cygpath --Path - Windows" $ catalina_tmpdir "`

ClassPath = `Cygpath --Path - Windows" $ ClassPath "` jsse_home = `cygpath --Path - Windows" $ jsse_home "`

Fi

# Display information, then execute the command

Echo "Using Catalina_Base: $ CATALINA_BASE"

Echo "Using Catalina_Home: $ CATALINA_HOME"

Echo "Using Catalina_TMPDir: $ Catalina_TMPDIR"

Echo "Using Java_Home: $ java_home"

# ...... When performing Catalina.sh, it is JPDA ...

IF [$ 1 "=" jpda "]; then

IF [-z "$ JPDA_TRANSPORT"]; then

JPDA_TRANSPORT = "dt_socket"

Fi

IF [-z "$ jpda_address"]; then

JPDA_ADDRESS = "8000"

Fi

IF [-z "$ JPDA_OPTS"]; then

JPDA_OPTS = "- XDebug -xrunjdwp: Transport = $ JPDA_TRANSPORT, Address = $ JPDA_ADDRESS, Server = Y, SUSPEND = N"

Fi

Catalina_opts = "$ CATALINA_OPTS $ JPDA_OPTS"

Shift

Fi

# ...... When performing Catalina.sh, it is debug ...

IF [$ 1 "=" debug "]; then

Shift

IF [$ 1 "=" -security "]; then

Echo "Using Security Manager"

Shift

Exec "$ _RunJDB" $ java_opts $ CATALINA_OPTS /

-Djava.endorsed.dirs = "$ java_endorsed_dirs" -classpath "$ classpath" /

-SourcePath "$ CATALINA_HOME" /../../ jakarta-tomcat-4.0 / catalina / src / share /

-Djava.security.manager /

-Djava.security.policy == "$ CATALINA_BASE" /CONF/CATALINA.POLICY /

-Dcatalina.base = "$ CATALINA_BASE" /

-Dcatalina.home = "$ CATALINA_HOME" /

-Djava.io.tmpdir = "$ CATALINA_TMPDIR" /

Org.apache.catalina.Startup.bootstrap "$ @" start

Else

Exec "$ _RunJDB" $ java_opts $ CATALINA_OPTS /

-Djava.endorsed.dirs = "$ java_endorsed_dirs" -classpath "$ ClassPath" / -SourcePath "$ CATALINA_HOME" /../../ jakarta-tomcat-4.0 / catalina / src / share /

-Dcatalina.base = "$ CATALINA_BASE" /

-Dcatalina.home = "$ CATALINA_HOME" /

-Djava.io.tmpdir = "$ CATALINA_TMPDIR" /

Org.apache.catalina.Startup.bootstrap "$ @" start

Fi

# ...... When performing Catalina.sh, it is Embedded ...

Elif ["$ 1" = "Embedded"];.

Shift

Echo "Embedded ClassPath: $ Classpath"

Exec "$ _Runjava" $ java_opts $ CATALINA_OPTS /

-Djava.endorsed.dirs = "$ java_endorsed_dirs" -classpath "$ classpath" /

-Dcatalina.base = "$ CATALINA_BASE" /

-Dcatalina.home = "$ CATALINA_HOME" /

-Djava.io.tmpdir = "$ CATALINA_TMPDIR" /

Org.apache.catalina.Startup.Embedded "$ @"

# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----

# | ...... When the parameter of the Catalina.sh is Run ... |

# | Start Tomcat Server in the current window! ! ! |

# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----

Elif ["$ 1" = "run"]; then

# 把 去 r掉

Shift

# If the parameter is Run -security, start the Security Manager

IF [$ 1 "=" -security "]; then

Echo "Using Security Manager"

Shift

Exec "$ _Runjava" $ java_opts $ CATALINA_OPTS /

-Djava.endorsed.dirs = "$ java_endorsed_dirs" -classpath "$ classpath" /

-Djava.security.manager /

-Djava.security.policy == "$ CATALINA_BASE" /CONF/CATALINA.POLICY /

-Dcatalina.base = "$ CATALINA_BASE" /

-Dcatalina.home = "$ CATALINA_HOME" /

-Djava.io.tmpdir = "$ CATALINA_TMPDIR" /

Org.apache.catalina.startup.bootstrap "$ @" Start # If the parameter is a lonely RUN, start the Tomcat server in this window

# In this window, the method started in this window is to use EXEC, let the current process fork a new process to start Tomcat, the current process is the parent process of Tomcat

# 启 启 Tomcat class is org.apache.catalina.startup.bootstrap.main ("start");

Else

Exec "$ _Runjava" $ java_opts $ CATALINA_OPTS /

-Djava.endorsed.dirs = "$ java_endorsed_dirs" -classpath "$ classpath" /

-Dcatalina.base = "$ CATALINA_BASE" /

-Dcatalina.home = "$ CATALINA_HOME" /

-Djava.io.tmpdir = "$ CATALINA_TMPDIR" /

Org.apache.catalina.Startup.bootstrap "$ @" start

Fi

# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----

# | ...... When performing the parameters of Catalina.sh, it is START ... |

# | Start Tomcat Server in a new window! ! ! |

# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----

Elif ["$ 1" = "start"]; then

# Remove the parameter start

Shift

# Create a file (if the file does not exist) $ Catalina_Base / Logs / Catalina.out

Touch "$ Catalina_Base" /logs/catalina.out

# If the parameter is start -security, start the Security Manager

IF [$ 1 "=" -security "]; then

Echo "Using Security Manager"

Shift

"$ _Runjava" $ java_opts $ CATALINA_OPTS /

-Djava.endorsed.dirs = "$ java_endorsed_dirs" -classpath "$ classpath" /

-Djava.security.manager /

-Djava.security.policy == "$ CATALINA_BASE" /CONF/CATALINA.POLICY /

-Dcatalina.base = "$ CATALINA_BASE" /

-Dcatalina.home = "$ CATALINA_HOME" /

-Djava.io.tmpdir = "$ CATALINA_TMPDIR" /

Org.apache.catalina.startup.bootstrap "$ @" start /

>> "$ CATALINA_BASE" /LOGS/CATALINA.OUT 2> & 1 &

IF [! -z "$ CATALINA_PID"]; Thenecho $!> $ CATALINA_PID

Fi

# If the parameter is a START, then start Tomcat in a new window

Else

"$ _Runjava" $ java_opts $ CATALINA_OPTS /

-Djava.endorsed.dirs = "$ java_endorsed_dirs" -classpath "$ classpath" /

-Dcatalina.base = "$ CATALINA_BASE" /

-Dcatalina.home = "$ CATALINA_HOME" /

-Djava.io.tmpdir = "$ CATALINA_TMPDIR" /

Org.apache.catalina.startup.bootstrap "$ @" start /

>> "$ CATALINA_BASE" /LOGS/CATALINA.OUT 2> & 1 &

IF [! -z "$ Catalina_PID"]; then

Echo $!> $ CATALINA_PID

Fi

Fi

# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----

# | ...... When performing the parameters of Catalina.sh, it is STOP ... |

# | Close Tomcat server! ! ! |

# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----

Elif ["$ 1" = "stop"]; then

# Remove the parameter stop

Shift

# Close the class of the Tomcat server is org.apache.catalina.startup.bootstrap-> main ("stop");

# Note: Java -d is setting system properties

Exec "$ _Runjava" $ java_opts $ CATALINA_OPTS /

-Djava.endorsed.dirs = "$ java_endorsed_dirs" -classpath "$ classpath" /

-Dcatalina.base = "$ CATALINA_BASE" /

-Dcatalina.home = "$ CATALINA_HOME" /

-Djava.io.tmpdir = "$ CATALINA_TMPDIR" /

Org.apache.catalina.startup.bootstrap "$ @" stop

# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----

# | ...... When performing the parameters of Catalina.sh, it is unrecognizable ... |

# | Print Help Information, thereby viewing the meaning of various parameters representing! ! ! |

# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----

Else

echo "Usage: Catalina.sh (Commands ...)

echo "Commands:"

Echo "Debug Start Catalina in a Debugger" Echo "Debug -security Debug Catalina with a security manager"

Echo "Embedded Start Catalina in Embedded Mode"

Echo "JPDA Start Start Catalina Under JPDA Debugger"

Echo "Run Start Catalina In The Current WinDow"

Echo "Run -security Start In The Current Window with Security Manager"

Echo "Start Start Catalina in a Separate Window"

Echo "Start-Security Start in a Separate Window with security manager"

Echo "Stop Stop Catalina"

EXIT 1

Fi

转载请注明原文地址:https://www.9cbs.com/read-8526.html

New Post(0)