Tomcat启动脚本catalina.sh
heavyz, 2003-03-22
1 - 概述
脚本catalina.sh用于启动和关闭tomcat服务器,是最关键的脚本
另外的脚本startup.sh和shutdown.sh都是使用不同的参数调用了该脚本
该脚本的使用方法如下(引自该脚本本身):
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 - 脚本分析
#!/bin/sh
# =============================================================
# 该脚本设置正确的环境变量和系统信息,然后启动或者停止tomcat server
# 具体的操作是:
# 使用命令行参数作为args的实参,调用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 to.
#
# CATALINA_OPTS (Optional) Java runtime options used when the "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 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_socket".
#
# 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 should 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=false
case "`uname`" in
CYGWIN*) cygwin=true;;
esac
# PRG是被执行的脚本的名称,可以认为PRG=="catalina.sh",也可能是某个符号链,指向该脚本。
PRG="$0"
# 处理了一下PRG,等循环跳出之后PRG成为 ????
while [ -h "$PRG" ]; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '.*/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`/"$link"
fi
done
# PRGDIR是PRG的目录路径名称
PRGDIR=`dirname "$PRG"`
# 执行$CATALINA_HOME/BIN/setenv.sh来设置环境变量
# [ -r filename ] 是判断是否文件存在且可读
CATALINA_HOME=`cd "$PRGDIR/.." ; pwd`
if [ -r "$CATALINA_HOME"/bin/setenv.sh ]; then
. "$CATALINA_HOME"/bin/setenv.sh
fi
# For Cygwin, 确保所有的路径名都符合UNIX格式
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
# 设置用来初始化SystemClassLoader的CLASSPATH变量:通过执行脚本setclasspath.sh完成
# 注意:脚本setclasspath.sh改变了原来的$CLASSPATH变量,而把它设为:
# CLASSPATH=$CATALINA_HOME/bin/bootstrap.jar:$JAVA_HOME/lib/tools.jar
# 其中bootstrap.jar是package org.apache.catalina.startup的打包文件,
# 含有启动方法org.apache.catalina.startup.Bootstrap.main(String[] args)
# tools.jar含有javac编译器,用来把jsp文件编译成为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 needed to run this program"
exit 1
fi
# 在CLASSPATH环境变量后面补上一些JAR文件
# [ -n string ] 判断字符串是否长度非0;[ -z string ] 判断字符串是否长度为0
# 它们可以用来判断是否某个环境变量已经被设置
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
# 指定CATALINA_BASE变量
# 如果CATALINA_BASE没有值,就让CATALINA_BASE=$CATALINA_HOME
if [ -z "$CATALINA_BASE" ] ; then
CATALINA_BASE="$CATALINA_HOME"
fi
# 指定CATALINA_TMPDIR变量
# 如果CATALINA_TMPDIR没有值,就让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, 在执行java程序前把路径名转换成WINDOWS格式
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
# 显示信息,然后执行命令
echo "Using CATALINA_BASE: $CATALINA_BASE"
echo "Using CATALINA_HOME: $CATALINA_HOME"
echo "Using CATALINA_TMPDIR: $CATALINA_TMPDIR"
echo "Using JAVA_HOME: $JAVA_HOME"
# ......当执行catalina.sh的参数是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
# ......当执行catalina.sh的参数是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
# ......当执行catalina.sh的参数是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 "$@"
# +----------------------------------------------------+
# | ......当执行catalina.sh的参数是run的时候...... |
# | 在当前窗口中启动tomcat服务器!!! |
# +----------------------------------------------------+
elif [ "$1" = "run" ]; then
# 把参数run去掉
shift
# 如果参数是run -security,则启动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
# 如果参数是孤单的run,则在本窗口中启动tomcat服务器
# 在本窗口中启动的方法是使用exec,让当前进程fork一个新进程来启动tomcat,当前进程是tomcat的父进程
# 启动tomcat的类是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
# +----------------------------------------------------+
# | ......当执行catalina.sh的参数是start的时候...... |
# | 在新窗口中启动tomcat服务器!!! |
# +----------------------------------------------------+
elif [ "$1" = "start" ] ; then
# 把参数start去掉
shift
# 创建一个文件(如果文件不存在的话)$CATALINA_BASE/logs/catalina.out
touch "$CATALINA_BASE"/logs/catalina.out
# 如果参数是start -security,则启动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" ]; then
echo $! > $CATALINA_PID
fi
# 如果参数是孤单的start,那么在新窗口中启动tomcat
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
# +----------------------------------------------------+
# | ......当执行catalina.sh的参数是stop的时候...... |
# | 关闭tomcat服务器!!! |
# +----------------------------------------------------+
elif [ "$1" = "stop" ] ; then
# 把参数stop去掉
shift
# 关闭tomcat服务器的类是org.apache.catalina.startup.Bootstrap->main("stop");
# 注意:java -D 是设置系统属性
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
# +----------------------------------------------------+
# | ......当执行catalina.sh的参数不可辨认的时候...... |
# | 打印帮助信息,由此查看各种参数代表的意义!!! |
# +----------------------------------------------------+
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
heavyz, 2003-03-22
1 - 概述
脚本catalina.sh用于启动和关闭tomcat服务器,是最关键的脚本
另外的脚本startup.sh和shutdown.sh都是使用不同的参数调用了该脚本
该脚本的使用方法如下(引自该脚本本身):
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 - 脚本分析
#!/bin/sh
# =============================================================
# 该脚本设置正确的环境变量和系统信息,然后启动或者停止tomcat server
# 具体的操作是:
# 使用命令行参数作为args的实参,调用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 to.
#
# CATALINA_OPTS (Optional) Java runtime options used when the "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 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_socket".
#
# 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 should 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=false
case "`uname`" in
CYGWIN*) cygwin=true;;
esac
# PRG是被执行的脚本的名称,可以认为PRG=="catalina.sh",也可能是某个符号链,指向该脚本。
PRG="$0"
# 处理了一下PRG,等循环跳出之后PRG成为 ????
while [ -h "$PRG" ]; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '.*/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`/"$link"
fi
done
# PRGDIR是PRG的目录路径名称
PRGDIR=`dirname "$PRG"`
# 执行$CATALINA_HOME/BIN/setenv.sh来设置环境变量
# [ -r filename ] 是判断是否文件存在且可读
CATALINA_HOME=`cd "$PRGDIR/.." ; pwd`
if [ -r "$CATALINA_HOME"/bin/setenv.sh ]; then
. "$CATALINA_HOME"/bin/setenv.sh
fi
# For Cygwin, 确保所有的路径名都符合UNIX格式
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
# 设置用来初始化SystemClassLoader的CLASSPATH变量:通过执行脚本setclasspath.sh完成
# 注意:脚本setclasspath.sh改变了原来的$CLASSPATH变量,而把它设为:
# CLASSPATH=$CATALINA_HOME/bin/bootstrap.jar:$JAVA_HOME/lib/tools.jar
# 其中bootstrap.jar是package org.apache.catalina.startup的打包文件,
# 含有启动方法org.apache.catalina.startup.Bootstrap.main(String[] args)
# tools.jar含有javac编译器,用来把jsp文件编译成为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 needed to run this program"
exit 1
fi
# 在CLASSPATH环境变量后面补上一些JAR文件
# [ -n string ] 判断字符串是否长度非0;[ -z string ] 判断字符串是否长度为0
# 它们可以用来判断是否某个环境变量已经被设置
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
# 指定CATALINA_BASE变量
# 如果CATALINA_BASE没有值,就让CATALINA_BASE=$CATALINA_HOME
if [ -z "$CATALINA_BASE" ] ; then
CATALINA_BASE="$CATALINA_HOME"
fi
# 指定CATALINA_TMPDIR变量
# 如果CATALINA_TMPDIR没有值,就让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, 在执行java程序前把路径名转换成WINDOWS格式
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
# 显示信息,然后执行命令
echo "Using CATALINA_BASE: $CATALINA_BASE"
echo "Using CATALINA_HOME: $CATALINA_HOME"
echo "Using CATALINA_TMPDIR: $CATALINA_TMPDIR"
echo "Using JAVA_HOME: $JAVA_HOME"
# ......当执行catalina.sh的参数是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
# ......当执行catalina.sh的参数是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
# ......当执行catalina.sh的参数是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 "$@"
# +----------------------------------------------------+
# | ......当执行catalina.sh的参数是run的时候...... |
# | 在当前窗口中启动tomcat服务器!!! |
# +----------------------------------------------------+
elif [ "$1" = "run" ]; then
# 把参数run去掉
shift
# 如果参数是run -security,则启动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
# 如果参数是孤单的run,则在本窗口中启动tomcat服务器
# 在本窗口中启动的方法是使用exec,让当前进程fork一个新进程来启动tomcat,当前进程是tomcat的父进程
# 启动tomcat的类是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
# +----------------------------------------------------+
# | ......当执行catalina.sh的参数是start的时候...... |
# | 在新窗口中启动tomcat服务器!!! |
# +----------------------------------------------------+
elif [ "$1" = "start" ] ; then
# 把参数start去掉
shift
# 创建一个文件(如果文件不存在的话)$CATALINA_BASE/logs/catalina.out
touch "$CATALINA_BASE"/logs/catalina.out
# 如果参数是start -security,则启动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" ]; then
echo $! > $CATALINA_PID
fi
# 如果参数是孤单的start,那么在新窗口中启动tomcat
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
# +----------------------------------------------------+
# | ......当执行catalina.sh的参数是stop的时候...... |
# | 关闭tomcat服务器!!! |
# +----------------------------------------------------+
elif [ "$1" = "stop" ] ; then
# 把参数stop去掉
shift
# 关闭tomcat服务器的类是org.apache.catalina.startup.Bootstrap->main("stop");
# 注意:java -D 是设置系统属性
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
# +----------------------------------------------------+
# | ......当执行catalina.sh的参数不可辨认的时候...... |
# | 打印帮助信息,由此查看各种参数代表的意义!!! |
# +----------------------------------------------------+
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
相关推荐
针对这个问题,给出的解决方案是在Tomcat的启动脚本`bin/catalina.sh`中添加以下配置: ```bash JAVA_OPTS="-Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8" ``` 这里的`JAVA_OPTS`环境变量用于设置Java虚拟机...
Catalina.sh是Tomcat服务器的启动脚本,它包含了启动、停止和管理Tomcat实例的命令。而JConsole是Java的内置性能监视工具,可以帮助开发者监控Java应用程序的内存使用、线程状态、类加载、JVM垃圾收集等信息。 首先...
默认情况下,Tomcat的主要日志输出文件是`catalina.out`,它记录了服务器启动、运行和关闭过程中的所有标准输出和错误信息。然而,随着服务器运行时间的增长,`catalina.out`可能会变得非常大,导致日志查找和分析变...
《catalina.sh详解——深度剖析Tomcat启动脚本》 在Java Web开发领域,Tomcat作为一款广泛应用的开源Servlet容器,其启动、管理和监控离不开一个核心脚本——`catalina.sh`。这个脚本是Tomcat服务器的启动入口,...
`catalina.sh`是Tomcat的启动脚本,它负责启动、停止和管理Tomcat实例。 - 当Tomcat运行时,所有标准输出(stdout)和标准错误(stderr)都会被重定向到`catalina.out`,这对于调试和问题排查非常有帮助。 - 但是...
- 打开Tomcat的启动脚本`catalina.sh`,通常位于`/path/to/tomcat/bin/`目录下。 - 修改脚本中的日志输出方式,使其支持cronolog。具体操作是在`catalina.sh`文件中找到与日志输出相关的代码段,将其修改为如下所...
Linux下,tomcat自动获取CATALINA_HOME的脚本,放到startup.sh同级目录下即可
接下来,需要修改Tomcat的启动脚本`catalina.sh`,以便在启动时使用cronolog进行日志文件的切分。 #### 修改`catalina.sh` 1. **找到`catalina.sh`文件的位置**: 通常位于`$TOMCAT_HOME/bin`目录下。 2. **注释...
在Tomcat这样的Java应用服务器中,`catalina.out`是默认的日志文件,记录了Tomcat启动、运行过程中的所有信息,包括错误、警告以及普通日志。随着服务器运行时间的增长,`catalina.out`可能会变得非常庞大,不仅占用...
1. 在Tomcat的启动脚本(例如:catalina.sh)的合适位置添加以下JVM参数: ``` -Dcom.sun.management.config.file=catalina-logging.properties ``` 2. 在Tomcat的conf目录下创建catalina-logging.properties...
同时,确保Tomcat启动脚本(`catalina.sh`或`catalina.bat`)包含以下行来加载Log4j配置: ```bash -Dlog4j.configuration=file:${catalina.base}/conf/log4j.properties ``` 这样,Tomcat就会使用Log4j进行日志...
catalina.sh 是 Apache Tomcat 服务器的一部分,它是用于启动、停止和管理 Tomcat 服务的脚本。在这个上下文中,可能是指通过修改或扩展 catalina.sh 脚本来集成 cronolog,以便在 Tomcat 服务器运行时自动分割日志...
4. **启动与管理**:通过`bin`目录下的脚本启动Tomcat,如`./catalina.sh start`(Unix/Linux)或`catalina.bat start`(Windows)。可以通过`./catalina.sh stop`或`catalina.bat stop`来停止服务。`manager`和`...
在Linux环境下,`startup.sh`是bash脚本,通过执行`./startup.sh`命令来启动Tomcat。它会调用`catalina.sh`主脚本来执行实际的启动过程。在Windows中,`startup.bat`是批处理文件,同样会调用`catalina.bat`。启动...
这些参数通常在`catalina.sh`或`setenv.sh`脚本中设置。 10. **负载均衡与集群** 对于高可用性和负载均衡,可以配置多个Tomcat实例并通过反向代理(如Nginx或HAProxy)进行负载均衡。更高级的配置可以通过Apache ...
1. **bin**:包含启动和停止Tomcat的脚本,如`catalina.sh`、`startup.sh`和`shutdown.sh`,以及其他的实用工具。 2. **conf**:存放所有配置文件,如`server.xml`(服务器配置)、`context.xml`(全局上下文配置)...
在Tomcat中,启动脚本主要位于`bin`目录下,分为两个主要脚本:`catalina.sh`(Linux或Unix系统)和`catalina.bat`(Windows系统)。这些脚本负责初始化Java环境,设置系统路径,加载Tomcat服务器的类和配置,并最终...
这个压缩包包含了Tomcat的全部组件,如bin目录下的可执行脚本(如`catalina.sh`用于启动和停止Tomcat),conf目录下配置文件(如`server.xml`定义了服务器的配置),webapps目录用于存放Web应用,以及logs、temp、...
总结而言,通过创建Shell脚本并设置定时任务来定期执行,可以有效管理和控制Tomcat服务器的catalina.out文件大小,避免因磁盘空间耗尽而影响服务器的正常运行。这是一个对任何使用Tomcat的管理员都非常有价值的解决...