Tomcat servlet engine is not running, but pid file exists. What does this message mean? Do I need to recover Tomcat if I get it?

StackOverflow https://stackoverflow.com/questions/11812048

Question

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?

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
Was it helpful?

Solution

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.

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.

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.

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

OTHER TIPS

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.

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

For me problem has been resolved

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top