Tomcat STARTUP script Catalina. Sh

Source: Internet
Author: User
Tags stop script

From: http://www.huihoo.org/apache/tomcat/heavyz/02-catalina.sh.html

 

1-Overview

The script Catalina. Sh is the most critical script for starting and disabling Tomcat servers.
In addition, startup. SH and shutdown. Sh both use different parameters to call the script.
The script is used as follows (derived from the script itself ):

 

2-script analysis

#! /Bin/sh #=============================================== ====================================## this script sets the correct environment variables and system information, start or stop Tomcat server # the specific operation is: # Use the command line parameter as the real parameter of argS and call Org. apache. catalina. startup. bootstrap. main (string []) #===================================================== ==================================#####start/Stop script for the Catalina server ## environment Variabl E 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. # catalina_opts (optional) Java runtime options used when the "Start", # "stop", or "run" command is executed. # catalina_tmpdir (optional) direc Using path location of temporary directory # The JVM shocould 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 the "Start", # "stop", or "run" command is executed. # jpda_transport (optional) JPDA transport used when the "JPDA start" # command is executed. the default is "dt_soc Ket ". # jpda_address (optional) Java runtime options used when the "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 # system class path used to start Tomcat. # catalina_pid (optional) path of the file which shoshould contains the pid # Of Catalina startup Java Process, When start (fork) is used # --------------------------------------------------------------------------- # OS specific support. $ VaR _ must _ be set to either true or false. cygwin = falsecase "'uname'" incygwin *) cygwin = true; esac # PRG is the name of the executed script, which can be considered as PRG = "Catalina. sh ", or a symbolic chain pointing to the script. PRG = "$0" # After processing the PRG, The PRG becomes ???? While [-h "$ PRG"]; do ls = 'LS-LD "$ PRG" 'link = 'expr "$ ls ":'. *-> /(. */) $ ''if expr "$ link ":'. */. * '>/dev/NULL; then PRG = "$ link" else PRG = 'dirname "$ PRG" '/"$ link" fidone # prgdir is the PRG directory path name prgdir = 'dirname "$ PRG "' # Run $ catalina_home/bin/setenv. sh to set the environment variable # [-r filename] is to determine whether the file exists and read catalina_home = 'CD "$ prgdir /.. "; pwd' if [-R" $ catalina_home "/bin/setenv. sh]; then. "$ catalina_home"/bin/setenv. sh FI # For cygwin, make sure all path names comply with the 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: Execute the script setclasspath. sh complete # Note: The Script setclasspath. sh changed the original $ classpath variable and set it to: # classpath = $ catalina_home/bin/Bootstrap. jar: $ java_home/lib/tools. jar # Bootstrap. jar is package Org. apache. catalina. startup package file, # contains the startup method Org. apache. catalina. startup. bootstrap. main (string [] ARGs) # tools. jar contains the javac compiler, which is used to compile the JSP file into servlet classif [-R "$ catalina_home"/bin/setclasspath. sh]; Then basedir = "$ catalina_home ". "$ catalina_home"/bin/setclasspath. shelse echo "cannot find $ catalina_home/bin/setclasspath. sh "Echo" this file is needed to run this program "Exit 1fi # add some jar files after the classpath environment variable # [-N string] to determine whether the string length is not 0; [-Z string] determines whether the string length is 0 # They can be used to determine whether an environment variable has been set if [-n "$ jsse_home"]; then classpath = "$ classpath": "$ jsse_home"/lib/jcert. jar: "$ jsse_home"/lib/jnet. jar: "$ jsse_ho Me "/lib/JSSE. jarficlasspath = "$ classpath": "$ catalina_home"/bin/Bootstrap. jar # specify the catalina_base variable # If catalina_base has no value, make catalina_base = $ catalina_homeif [-z "$ catalina_base"]; then catalina_base = "$ catalina_home" fi # specify the catalina_tmpdir variable # If catalina_tmpdir has no value, make catalina_tmpdir = $ catalina_base/tempif [-z "$ catalina_tmpdir"] then # define the java. io. tmpdir to use for Catalina catalina_tmpdir = "$ catali Na_base "/tempfi # For cygwin, convert the path name to Windows format before running 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" 'f I # display information, and then run 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 Catalina. when the sh parameter 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_op TS = "-xdebug-xrunjdwp: Transport = $ jpda_transport, address = $ jpda_address, Server = Y, suspend = N "fi catalina_opts =" $ catalina_opts $ jpda_opts "shiftfi #...... when Catalina. when the sh parameter 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_en Dorsed_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 Catalina. when the sh parameter is embedded ...... elif ["$1" = "embedded"]; then 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 Catalina. when the sh parameter is run ...... | # | start the Tomcat server in the current window !!! | # + -------------------------------------------------- + Elif ["$1" = "run"]; then # Remove the parameter run shift # If the parameter is run-security, start 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/CA Talina. policy/-dcatalina. base = "$ catalina_base"/-dcatalina. home = "$ catalina_home"/-djava. io. tmpdir = "$ catalina_tmpdir"/org. apache. catalina. startup. bootstrap "$ @" start # If the parameter is run alone, start the Tomcat server in this window # The method to start 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 # The Tomcat startup class is Org. apache. catalina. startup. bootstrap. main ("START"); else EXEC "$ _ runjava" $ java_opts $ catalina_opts/-djava. endorsed. dir S = "$ 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 Catalina. when the sh parameter is start ...... | # | start the Tomcat server in a new window !!! | # + -------------------------------------------------- + Elif ["$1" = "start"]; then # Remove the start parameter 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 security manager if ["$1" = "-Security"]; then ECHO "using security manager" shift "$ _ runjava" $ java_opts $ catalina_opts/-djava. endorsed. dirs = "$ java_endorsed_dirs"-clas Spath "$ 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"]; Then ECHO $!> $ Catalina_pid fi # If the parameter is a standalone start, start Tomcat else "$ _ runjava" $ java_opts $ catalina_opts/-djava in the new window. 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 # + ------------------------------------------------------ + # | ...... when Catalina. when the sh parameter is stop ...... | # | disable the Tomcat server !!! | # + -------------------------------------------------- + Elif ["$1" = "stop"]; then # Remove the parameter stop shift # the class for disabling the Tomcat server is Org. apache. catalina. startup. bootstrap-> main ("stop"); # Note: Java-D sets the system attribute 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 = "$ ca Talina_tmpdir "/org. apache. catalina. startup. bootstrap "$ @" stop # + ---------------------------------------------------- + # | ...... when Catalina. when sh parameters are unidentifiable ...... | # | print the help information to view the meaning of various parameters !!! | # + ---------------------------------------------------- + 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 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 Catalina in a separate window "Echo" start-Security start in a separate window with security manager "Echo" Stop Catalina "Exit 1fi
  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"

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.