有时如果重启后相同的 pid 正在运行,tomcat 将无法启动
我的 pid 文件位于 apache-tomcat/temp/tomcat.pid
作为解决方案,我只检查 PID 是否属于 Catalina
更改文件 apache-tomcat/bin/catalina.sh 关于第 386 行
从ps -p $PID >/dev/null 2>&1
到ps -fp $PID |grep catalina >/dev/null 2>&1
摘自 catalina.sh 文件
if [ ! -z "$CATALINA_PID" ]; then
if [ -f "$CATALINA_PID" ]; then
if [ -s "$CATALINA_PID" ]; then
echo "Existing PID file found during start."
if [ -r "$CATALINA_PID" ]; then
PID=`cat "$CATALINA_PID"`
ps -fp $PID |grep catalina >/dev/null 2>&1 #this line
if [ $? -eq 0 ] ; then
echo "Tomcat appears to still be running with PID $PID. Start aborted."
echo "If the following process is not a Tomcat process, remove the PID file and try again:"
ps -f -p $PID
exit 1
else
echo "Removing/clearing stale PID file."
rm -f "$CATALINA_PID" >/dev/null 2>&1
if [ $? != 0 ]; then
if [ -w "$CATALINA_PID" ]; then
cat /dev/null > "$CATALINA_PID"
else
echo "Unable to remove or clear stale PID file. Start aborted."
exit 1
fi
fi
fi
else
echo "Unable to read PID file. Start aborted."