Tomcat servlet引擎没有运行,但是pid文件存在。这条信息是什么意思?如果我得到Tomcat,我需要恢复吗?

时间:2023-01-26 16:26:20

I am making a shell script to restart tomcat after crash. I wonder I need to handle this message in my script "Tomcat servlet engine is not running, but pid file exists." What does this message means? Do I need to take it into account as an error message that oblige me to restart Tomcat?

我正在制作一个shell脚本来在崩溃后重启tomcat。我想知道我需要在我的脚本中处理这个消息“Tomcat servlet引擎没有运行,但是pid文件存在。”这个消息的意思是什么?我是否需要将它考虑为一个错误消息,迫使我重新启动Tomcat?

My script is as follow:

我的剧本如下:

#!/bin/bash
SERVICE=/etc/init.d/tomcat7
STOPPED_MESSAGE=" * Tomcat servlet container is not running."  
PID_FILE_MESSAGE=" * Tomcat servlet engine is not running, but pid file exists."

if [ "`$SERVICE status`" == "$STOPPED_MESSAGE" ];
then  
{
    $SERVICE start
}
else
    if [ "`$SERVICE status`" == "$PID_FILE_MESSAGE" ];
    then
    {
        $SERVICE restart
    }
    fi
fi

2 个解决方案

#1


4  

Here's the definition of PID. A PID file is a file that contains a process identifier. If Tomcat's startup scripts are run with CATALINA_PID environment variable set properly, then the PID of the Tomcat process will be recorded to a file upon startup. If the file exists when you try to start Tomcat, the scripts will refuse to run because it does not want to clobber a (possibly valid) PID file.

这是PID的定义。PID文件是包含进程标识符的文件。如果Tomcat的启动脚本运行的是CATALINA_PID环境变量设置,那么Tomcat进程的PID将会在启动时被记录到一个文件中。如果在尝试启动Tomcat时存在该文件,脚本将拒绝运行,因为它不希望clobber(可能是有效的)PID文件。

If you are sure that Tomcat is not running, simply delete the file (it should be available through the CATALINA_PID environment variable) and try again.

如果您确定Tomcat没有运行,只需删除该文件(它应该通过CATALINA_PID环境变量可用),然后再试一次。

I share @jordanm's comment about using exit codes instead of checking for specific (text) output: the latest version of Tomcat does not even use the messages that you have shown above, so it's very fragile.

我分享了@jordanm关于使用退出代码而不是检查特定(文本)输出的评论:最新版本的Tomcat甚至不使用您上面显示的消息,因此它非常脆弱。

If you want a self-re-starting service, considering looking at jsvc, which actually ships with Tomcat binaries in source form.

如果您想要一个自重新启动的服务,考虑查看jsvc,它实际上是使用源代码形式的Tomcat二进制文件。

#2


1  

I had a same problem when i restart the tomcat. Also i found "java.net.BindException: Cannot assign requested address" in cataline.out log file.

当我重启tomcat时,我遇到了同样的问题。我还发现了“java.net.BindException:无法在cataline中分配请求的地址”。日志文件。

Soultion: Kill all the java pid by using killall -9 java the restart the tomcat again.

通过使用killall -9 java来杀死所有的java pid,重新启动tomcat。

For me problem has been resolved

对我来说,问题已经解决了。

#1


4  

Here's the definition of PID. A PID file is a file that contains a process identifier. If Tomcat's startup scripts are run with CATALINA_PID environment variable set properly, then the PID of the Tomcat process will be recorded to a file upon startup. If the file exists when you try to start Tomcat, the scripts will refuse to run because it does not want to clobber a (possibly valid) PID file.

这是PID的定义。PID文件是包含进程标识符的文件。如果Tomcat的启动脚本运行的是CATALINA_PID环境变量设置,那么Tomcat进程的PID将会在启动时被记录到一个文件中。如果在尝试启动Tomcat时存在该文件,脚本将拒绝运行,因为它不希望clobber(可能是有效的)PID文件。

If you are sure that Tomcat is not running, simply delete the file (it should be available through the CATALINA_PID environment variable) and try again.

如果您确定Tomcat没有运行,只需删除该文件(它应该通过CATALINA_PID环境变量可用),然后再试一次。

I share @jordanm's comment about using exit codes instead of checking for specific (text) output: the latest version of Tomcat does not even use the messages that you have shown above, so it's very fragile.

我分享了@jordanm关于使用退出代码而不是检查特定(文本)输出的评论:最新版本的Tomcat甚至不使用您上面显示的消息,因此它非常脆弱。

If you want a self-re-starting service, considering looking at jsvc, which actually ships with Tomcat binaries in source form.

如果您想要一个自重新启动的服务,考虑查看jsvc,它实际上是使用源代码形式的Tomcat二进制文件。

#2


1  

I had a same problem when i restart the tomcat. Also i found "java.net.BindException: Cannot assign requested address" in cataline.out log file.

当我重启tomcat时,我遇到了同样的问题。我还发现了“java.net.BindException:无法在cataline中分配请求的地址”。日志文件。

Soultion: Kill all the java pid by using killall -9 java the restart the tomcat again.

通过使用killall -9 java来杀死所有的java pid,重新启动tomcat。

For me problem has been resolved

对我来说,问题已经解决了。