Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

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
like image 856
Rami Avatar asked Aug 04 '12 21:08

Rami


People also ask

How do I know if Tomcat is running?

Use a browser to check whether Tomcat is running on URL http://localhost:8080 , where 8080 is the Tomcat port specified in conf/server. xml. If Tomcat is running properly and you specified the correct port, the browser displays the Tomcat homepage.

How do I know if Tomcat is running on Linux?

A simple way to see if Tomcat is running is to check if there is a service listening on TCP port 8080 with the netstat command. This will, of course, only work if you are running Tomcat on the port you specify (its default port of 8080, for example) and not running any other service on that port.

Where is the Tomcat pid file?

It is already easy enough to kill with a script. For one, the pid is contained in a file, either under the Tomcat directory, or somewhere under var, inspect the catalina.sh and/or setenv.sh scripts to find out exactly where. Quack !


2 Answers

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.

like image 185
Christopher Schultz Avatar answered Oct 22 '22 20:10

Christopher Schultz


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

like image 1
Vijayaanand Maduraiveeran Avatar answered Oct 22 '22 21:10

Vijayaanand Maduraiveeran