粗体字部分是我的注释,可能对那些不太熟悉Shell 的人有点帮助吧,等你读懂了,再去配置心里就有底了。
#!/bin/sh
#......
# limitations under the License.
#......
# $Id: catalina.sh 750920 2009-03-06 14:43:19Z markt $
# -----------------------------------------------------------------------------
# OS specific support. $var _must_ be set to either true or false.
cygwin=false
os400=false
darwin=false
#uname 命令用于显示操作系统名称, `...` 命令替换,将反引号中的字符串做为命令来执行
case "`uname`" in
CYGWIN*) cygwin=true;;
OS400*) os400=true;;
Darwin*) darwin=true;;
#case 结束
esac
# resolve links - $0 may be a softlink
# $0 程序的执行名,可能是./catalish.sh
PRG="$0"
#文件测试,-h ,表示为符号链接,即软连接
while [ -h "$PRG" ]; do
ls=`ls -ld "$PRG"`
#expr 模式匹配,group 用法,返回匹配的内容,抽取最后一个软连接-> 所指向的文件,即*-> 后面的部分,也就是要执行的文件了
link=`expr "$ls" : '.*-> \(.*\)$'`
#>/dev/null 输出到空设备,一般Expr 模式匹配,返回匹配到的个数,判断link 变量中是否有‘/’
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`/"$link"
fi
done
# Get standard environment variables
# dirname 找出文件所在文件夹,可能是.
PRGDIR=`dirname "$PRG"`
# Only set CATALINA_HOME if not already set
#-z 字符串为空,执行命令替换,设定Catalina_home
[ -z "$CATALINA_HOME" ] && CATALINA_HOME=`cd "$PRGDIR/.." ; pwd`
#-r,文件属性,存在并且可读
if [ -r "$CATALINA_BASE"/bin/setenv.sh ]; then
. "$CATALINA_BASE"/bin/setenv.sh
elif [ -r "$CATALINA_HOME"/bin/setenv.sh ]; then
. "$CATALINA_HOME"/bin/setenv.sh
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$JRE_HOME" ] && JRE_HOME=`cygpath --unix "$JRE_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 --absolute --unix "$JSSE_HOME"`
fi
# For OS400
if $os400; then
# Set job priority to standard for interactive (interactive - 6) by using
# the interactive priority - 6, the helper threads that respond to requests
# will be running at the same priority as interactive jobs.
COMMAND='chgjob job('$JOBNAME') runpty(6)'
system $COMMAND
# Enable multi threading
export QIBM_MULTI_THREADED=Y
fi
# Get standard Java environment variables
if $os400; then
# -r will Only work on the os400 if the files are:
# 1. owned by the user
# 2. owned by the PRIMARY group of the user
# this will not work if the user belongs in secondary groups
BASEDIR="$CATALINA_HOME"
. "$CATALINA_HOME"/bin/setclasspath.sh
else
#设定Classpath
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
fi
# Add on extra jar files to CLASSPATH
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
#-z,字符串为空,设定Base = home
if [ -z "$CATALINA_BASE" ] ; then
CATALINA_BASE="$CATALINA_HOME"
fi
#按默认值设定Temp 文件夹
if [ -z "$CATALINA_TMPDIR" ] ; then
# Define the java.io.tmpdir to use for Catalina
CATALINA_TMPDIR="$CATALINA_BASE"/temp
fi
# Bugzilla 37848: When no TTY is available, don't output to console
have_tty=0
if [ "`tty`" != "not a tty" ]; then
have_tty=1
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
JAVA_HOME=`cygpath --absolute --windows "$JAVA_HOME"`
JRE_HOME=`cygpath --absolute --windows "$JRE_HOME"`
CATALINA_HOME=`cygpath --absolute --windows "$CATALINA_HOME"`
CATALINA_BASE=`cygpath --absolute --windows "$CATALINA_BASE"`
CATALINA_TMPDIR=`cygpath --absolute --windows "$CATALINA_TMPDIR"`
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$JSSE_HOME" ] && JSSE_HOME=`cygpath --absolute --windows "$JSSE_HOME"`
JAVA_ENDORSED_DIRS=`cygpath --path --windows "$JAVA_ENDORSED_DIRS"`
fi
# Set juli LogManager config file if it is present and an override has not been issued
#指定默认的Log 配置
if [ -z "$LOGGING_CONFIG" ]; then
if [ -r "$CATALINA_BASE"/conf/logging.properties ]; then
LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
else
# Bugzilla 45585
LOGGING_CONFIG="-Dnop"
fi
fi
#设定默认的日志管理器
if [ -z "$LOGGING_MANAGER" ]; then
JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
else
JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER"
fi
# ----- Execute The Requested Command -----------------------------------------
# Bugzilla 37848: only output this if we have a TTY
if [ $have_tty -eq 1 ]; then
echo "Using CATALINA_BASE: $CATALINA_BASE"
echo "Using CATALINA_HOME: $CATALINA_HOME"
echo "Using CATALINA_TMPDIR: $CATALINA_TMPDIR"
if [ "$1" = "debug" -o "$1" = "javac" ] ; then
echo "Using JAVA_HOME: $JAVA_HOME"
else
echo "Using JRE_HOME: $JRE_HOME"
fi
fi
#接收参数
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_SUSPEND" ]; then
JPDA_SUSPEND="n"
fi
if [ -z "$JPDA_OPTS" ]; then
JPDA_OPTS="-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND"
fi
CATALINA_OPTS="$CATALINA_OPTS $JPDA_OPTS"
#shift 参数提升,即$2 变$1...
shift
fi
if [ "$1" = "debug" ] ; then
if $os400; then
echo "Debug command not available on OS400"
exit 1
else
shift
if [ "$1" = "-security" ] ; then
echo "Using Security Manager"
shift
exec "$_RUNJDB" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
-sourcepath "$CATALINA_HOME"/../../java \
-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" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
-sourcepath "$CATALINA_HOME"/../../java \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
org.apache.catalina.startup.Bootstrap "$@" start
fi
fi
elif [ "$1" = "run" ]; then
shift
if [ "$1" = "-security" ] ; then
echo "Using Security Manager"
shift
exec "$_RUNJAVA" "$LOGGING_CONFIG" $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
else
#exec,执行指定的程序,$@ 代表所有的命令行参数
exec "$_RUNJAVA" "$LOGGING_CONFIG" $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
elif [ "$1" = "start" ] ; then
shift
touch "$CATALINA_BASE"/logs/catalina.out
if [ "$1" = "-security" ] ; then
echo "Using Security Manager"
shift
"$_RUNJAVA" "$LOGGING_CONFIG" $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 &
#2>&1,将错误信息合并到标准输出
if [ ! -z "$CATALINA_PID" ]; then
echo $! > $CATALINA_PID
fi
else
"$_RUNJAVA" "$LOGGING_CONFIG" $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
#将PID 记录到一个文件中,$$ 正在执行的PID,$! 后台运行的最后一个PID 值
echo $! > $CATALINA_PID
fi
fi
elif [ "$1" = "stop" ] ; then
shift
FORCE=0
if [ "$1" = "-force" ]; then
shift
FORCE=1
fi
"$_RUNJAVA" $JAVA_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
if [ $FORCE -eq 1 ]; then
if [ ! -z "$CATALINA_PID" ]; then
echo "Killing: `cat $CATALINA_PID`"
kill -9 `cat $CATALINA_PID`
else
echo "Kill failed: \$CATALINA_PID not set"
fi
fi
elif [ "$1" = "version" ] ; then
"$_RUNJAVA" \
-classpath "$CATALINA_HOME/lib/catalina.jar" \
org.apache.catalina.util.ServerInfo
else
#打印一堆的帮助和错误信息
echo "Usage: catalina.sh ( commands ... )"
echo "commands:"
if $os400; then
echo " debug Start Catalina in a debugger (not available on OS400)"
echo " debug -security Debug Catalina with a security manager (not available on OS400)"
else
echo " debug Start Catalina in a debugger"
echo " debug -security Debug Catalina with a security manager"
fi
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"
echo " stop -force Stop Catalina (followed by kill -KILL)"
echo " version What version of tomcat are you running?"
exit 1
fi
相关推荐
1. `bin`目录:包含了启动和停止Tomcat的脚本,如`catalina.bat`(Windows批处理文件)和`startup.sh`(Unix/Linux shell脚本)。还有一些其他工具,例如用于管理Tomcat的`tomcat-admin`和用于管理JAR文件的`jar.exe...
tomcat-catalina-jmx-remote-9.0.5 tomcat-catalina-jmx-remote-9.0.5.jar
6. **SSL/TLS支持**:Tomcat 8.5支持更强的加密标准,如TLSv1.3,以及更安全的加密套件,保护网络通信的安全。 7. **管理工具**:提供了一套管理工具,如`manager`应用和`admin`应用,用于部署、监控和管理应用。 ...
1. **bin目录**:这个目录包含了用于启动、停止和管理Tomcat的各种脚本,如`catalina.bat`(Windows批处理文件)和`startup.sh`(Unix/Linux shell脚本)。还有其他辅助工具,如`configtest.bat`用于检查Tomcat配置...
1. **bin目录**:包含启动和停止Tomcat的脚本,如`catalina.bat`、`startup.bat`和`shutdown.bat`,以及JAR文件,用于Tomcat的运行。 2. **conf目录**:存放Tomcat的主要配置文件,例如`server.xml`(定义服务器配置...
`catalina.sh`或`catalina.bat`启动脚本提供了多种启动模式,如"jpda"用于调试,"start"用于后台运行等。 总的来说,Apache Tomcat 8.5.81是一个功能强大且易用的Java Web服务器,适合从小型项目到大型企业级应用的...
1. **bin** 目录:包含了启动和停止Tomcat的脚本,如`startup.bat`和`shutdown.bat`,以及用于管理应用程序的工具,如`catalina.bat`和`tomcat7.exe`。 2. **conf** 目录:存储服务器配置文件,如`server.xml`...
Apache Tomcat 是一个开源软件应用服务器,主要用于部署和运行Java Servlet和JavaServer Pages(JSP)应用程序。这个压缩包文件 "apache-tomcat-8.5.97-windows-x.zip" 包含了Apache Tomcat 8.5.97 版本在Windows...
6. **Host**:在多域名环境中,Tomcat可以配置多个主机,每个主机都可以托管一个或多个Web应用程序。 7. **GlobalNamingResources**:提供全局资源,如数据源和邮件会话,可供所有部署的应用程序使用。 8. **...
- 配置环境变量:设置`CATALINA_HOME`指向Tomcat的安装目录,确保系统PATH变量包含 `%CATALINA_HOME%\bin`,以便于命令行调用Tomcat工具。 - 修改`conf/server.xml`:配置Tomcat服务器的主要设置,包括端口号、...
通常,可以使用`shutdown.sh`停止Tomcat,再用`startup.sh`启动,或者直接使用`catalina.sh`的start和stop选项。 值得注意的是,虽然此方法在很多情况下可以解决问题,但并非所有情况都适用。例如,如果日志输出被...
1. `bin`目录:包含了Tomcat的可执行脚本,如`catalina.bat`(Windows批处理文件)用于启动和停止Tomcat服务器,以及`startup.sh`和`shutdown.sh`(Unix/Linux脚本)。 2. `conf`目录:存放了Tomcat的配置文件,如`...
1. `bin`:包含启动和停止Tomcat的脚本,如`catalina.bat`(Windows下的批处理文件)、`startup.sh`(Unix/Linux的Shell脚本)以及其他管理和配置工具。 2. `conf`:存储所有配置文件,如`server.xml`定义了服务器的...
接着,配置环境变量,包括添加`CATALINA_HOME`指向Tomcat的安装目录,并将`PATH`环境变量添加 `%CATALINA_HOME%\bin`,以便在命令行中可以直接运行Tomcat的管理工具。 为了运行Tomcat,你需要先确保系统中已经安装...
`catalina.out`是Tomcat默认的日志文件,它记录了Tomcat启动、运行以及错误信息,对开发者和管理员来说非常重要。然而,如果不进行适当管理,这个日志文件可能会无限制增长,占用大量磁盘空间,甚至可能导致服务器...
6. 替换Tomcat的jar包:需要下载Log4j的jar包,比如log4j-1.2.17.jar,并将其与更新后的tomcat-juli-adapters.jar放入$CATALINA_HOME/lib目录下。同时,需要替换掉$CATALINA_HOME/bin目录下的tomcat-juli.jar。 7. ...
还可以使用`bin/catalina.sh`或`catalina.bat`脚本来控制更多服务选项。 6. **Web应用程序部署**:将WAR文件(Web应用程序的归档文件)放入`webapps`目录,Tomcat会自动检测并部署。或者,可以编辑`conf/server.xml...
默认情况下,Tomcat的主要日志输出文件是`catalina.out`,它记录了服务器启动、运行和关闭过程中的所有标准输出和错误信息。然而,随着服务器运行时间的增长,`catalina.out`可能会变得非常大,导致日志查找和分析变...
标题中的“在tomcat的catalina.sh文件中添加了jconsole检测内存配置”涉及到的是Java应用程序服务器Tomcat的配置以及使用JConsole进行性能监控的知识点。Tomcat是Apache软件基金会的一个开源项目,广泛用于部署Java ...
在深入探讨这个最新版之前,我们先了解一下Apache Tomcat的基本概念。Tomcat是一个轻量级应用服务器,相比于其他的Java EE应用服务器(如JBoss或WebLogic),它的体积更小,配置更简单,因此在小型项目或者开发测试...