[tomcat] Tomcat won't stop or restart

I tried stopping tomcat. It failed with this message:

  • Tomcat did not stop in time. PID file was not removed.

I then tried again and got this:

  • PID file (/opt/tomcat/work/catalina.pid) found but no matching process was found. Stop aborted.

I then tried starting tomcat in debug mode and got this:

  • PID file (/opt/tomcat/work/catalina.pid) found. Is Tomcat still running? Start aborted.

I them deleted /opt/tomcat/work/catalina.pid and tried restarting and got this:

  • $CATALINA_PID was set (/opt/tomcat/work/catalina.pid) but the specified file does not exist. Is Tomcat running? Stop aborted.

Anyone know how to get tomcat restarted?

This question is related to tomcat catalina

The answer is


In my case, the tomcat.pid is under /opt/tomcat/temp/. Tried to delete it manually. Still didn't work. After check setnev.sh in /opt/tomcat/bin/, notice there is a line of code to define JAVA_HOME:

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64/jre

Commented out this line, restart Tomcat. It works! Since I did a yum update and a new minor version of Java update coming from 1.8.0.212 to 1.8.0.222. Lessons learned: Hard-code should be avoided.


Follow this :)

  1. Open : /etc/systemd/system/tomcat.service

Can you see JAVA_HOME ? : modify it like below

Environment="JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64"

At 1.11.0 - insert your own Jdk version

  1. systemctl daemon-reload

  2. sudo systemctl start tomcat


Now, in eclipse -> Add Server -> .....

Got struck at tomcat installation directory ??

  1. Extract the tomcat tar file you already downloaded.
  2. Now go back to eclipse -> add server -> Browse -> Point to extracted file (done in step 1 above :)

Comment if you get struck in somewhere else too )


You can go to the location ${CATALINA_HOME}/logs/ open catalina.pid. Here we will get the pid. then terminate the process. kill -9 pid


Have you try $ sudo ./catalina.sh stop? It worked in my case.


Recent I have met several times of stop abnormal. Although shutdown.sh provides some information, The situations are:

  • result of the command ps -ef| grep java is Null.
  • result of the command ps -ef| grep java is not null.

My opinion is just kill the process of Catalina and remove the pid file (In your situation is /opt/tomcat/work/catalina.pid.)

The result seems not so seriously to influence others.


The catalina.pid is missing in your case.

This file is located under {your_jira_dir}/work/catalina.pid and it contains the pid of the current instance of jira.

so

ps aux | grep jira
  • find the correct entry
  • Copy the PID of the output and create a file that only contains this PID. - Make sure it can be read and written by the user which runs jira.
  • Try to shutdown jira again.

Make sure Tomcat is not currently running and the PID file is removed. Them you should start Tomcat successfully.

If you start fresh then:

  1. Create setenv.sh file in <CATALINA_HOME>/bin.
  2. In it I set CATALINA_PID=/tmp/tomcat.pid (or other directory of your choice) so you have more control over the Tomcat process.

Then to start Tomcat find catalina.sh in <CATALINA_HOME>/bin and execute:

./catalina.sh start

and to stop it run:

./catalina.sh stop 10 -force

From catalina.sh script's doc:

./catalina.sh

Usage: catalina.sh ( commands ... )
commands:

start             Start Catalina in a separate window
stop              Stop Catalina, waiting up to 5 seconds for the process to end
stop n            Stop Catalina, waiting up to n seconds for the process to end
stop -force       Stop Catalina, wait up to 5 seconds and then use kill -KILL if still running
stop n -force     Stop Catalina, wait up to n seconds and then use kill -KILL if still running

Note: If you want to use -force flag then setting CATALINA_PID is mandatory.


FIRST --> rm catalina.engine

THEN -->./startup.sh

NEXT TIME you restart --> ./shutdown.sh -force


sometimes if the same pid is running after reboot tomcat will not start

my pid file was at apache-tomcat/temp/tomcat.pid

 change file apache-tomcat/bin/catalina.sh about line 386 
 from "ps -p $PID >/dev/null 2>&1"
 to "ps -fp $PID |grep catalina >/dev/null 2>&1"

excerpt from catalina.sh file

 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."

I faced the same problem as mentioned below.

PID file found but no matching process was found. Stop aborted.

Solution is to find the free space of the linux machine by using the following command

df -h

The above command shows my home directory was 100% used. Then identified which files to be removed by using the following command

du -h .

After removing, it was able to perform IO operation on the linux machine and the tomcat was able to start.


I had this error message having started up a second Tomcat server on a Linux server.

$CATALINA_PID was set but the specified file does not exist. Is Tomcat running? Stop aborted.

When starting up the 2nd Tomcat I had set CATALINA_PID as asked but my mistake was to set it to a directory (I assumed Tomcat would write a default file name in there with the pid).

The fix was simply to change my CATALINA_PID to add a file name to the end of it (I chose catalina.pid from the above examples). Next I went to the directory and did a simple:

touch catalina.pid

creating an empty file of the correct name. Then when I did my shutdown.sh I got the message back saying:

PID file is empty and has been ignored.
Tomcat stopped.

I didn't have the option to kill Tomcat as the JVM was in use so I was glad I found this.


sudo systemctl stop tomcat

did it for me


You can always try to kill the process in case you see this kind of issues. You can get the process ID either from PS or from pid file and kill the process.