目录
以Tomcat 9.0.30为例,参考资料:《Tomcat架构解析》
1. 启动入口
一般使用Tomcat,都是运行 $CATALINA_BASE/bin/startup.sh(CATALINA_BASE指Tomcat根目录),所以先来看该脚本的主要内容:
# resolve links - $0 may be a softlink
PRG="$0"
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=`dirname "$PRG"`
EXECUTABLE=catalina.sh
# Check that target executable exists
if $os400; then
# -x 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
eval
else
if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then
echo "Cannot find $PRGDIR/$EXECUTABLE"
echo "The file is absent or does not have execute permission"
echo "This file is needed to run this program"
exit 1
fi
fi
其实就是根据命令,解析出startup.sh所在位置,然后拼出catalina.sh的路径,并且执行该脚本。catalina.sh很长,所以不贴内容了,该脚本的主要功能就是配置环境变量,然后拼接Java命令,大概长这样:
eval exec "\&