You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2022/03/21 08:32:17 UTC

[Bug 65970] New: Tomcat cannot startup due to Stale PID

https://bz.apache.org/bugzilla/show_bug.cgi?id=65970

            Bug ID: 65970
           Summary: Tomcat cannot startup due to Stale PID
           Product: Tomcat 8
           Version: 8.5.77
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: eddie.wu@sap.com
  Target Milestone: ----

Here is the scenario when we encountered this issue. 
After rebooting the VM, stale PID file are kept and prevent the tomcat service
from starting up.

error log:
Existing PID file found during start. 
Tomcat appears to still be running with PID 554. Start abort
If the following process is not a Tomcat process, remove t
UID        PID  PPID  C STIME TTY          TIME CMD
root       554     2  0 01:31 ?        00:00:00 [kworker/0

root cause: 
after reboot, tomcat process disappeared, but its PID are kept.
and same PID happen to be used by other process after reboot.

refer to Bug 57801, and catalina.sh
I am wondering whether it is possible to check the timestamp of $CATALINA_PID
file right before line of script.
       PID=`cat "$CATALINA_PID"
and ignore it if CATALINA_PID timestamp is older than the time when reboot
happened.

I am not expert of scripting or cross platform, not sure whether there is a
safe way to implement this logic on all platform.

Please enhance the logic here if it is feasible.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 65970] Tomcat cannot startup due to Stale PID

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65970

--- Comment #3 from eddie.wu@sap.com ---
(In reply to Christopher Schultz from comment #1)
> This situation was probably caused by a very unusual circumstance, such as a
> power failure or kill-9 signal.
> 
> It's not clear what you are asking for, here. If CATALINA_PID exists and
> there is an existing process matching that PID, then Tomcat will not start
> because it looks like Tomcat is already running.
> 
> With a low PID like that, it's probably a process that runs on startup, and,
> with a stale PID file it's very likely to match another process that was
> started on startup as well.
> 
> A better solution for you might be to place your PID file on volatile
> storage, or somewhere the OS will clear-out upon reboot, like /tmp. Not all
> OSs clear-out /tmp on reboot, but some of them do. Another option would be
> to instruct your init system to delete certain files (including the Tomcat
> PID file) early-on in the boot process to make sure the PID file just
> doesn't exist at all.

thanks for your reply.

I am aware of the work around (or solution), that is to use /run to store file
$CATALINA_PID

just want to clarify why I think there is a potential enhancement here.

exactly I am talking about the case of power failure or kill-9 signal.
basically in such scenario, current scrip code will treat the stale PID (which
is generated before VM reboot) as current running tomcat process and hence
refuse to start Tomcat.

My expectation is that Tomcat script to ignore this stale PID and go ahead to
startup. And I propose to compare the time stamp of $CATALINA_PID file and the
time when reboot happened to judge whether it is a STALE PID.

From my perspective, if we enhance it like this, then we need not resort to
volatile storage like /run. and End user even will not notice such details. 

Or put it in another way, solution/enhancement from Tomcat is much better than
the solution/work around outside of Tomcat.

Thanks again for your understanding of my end user perspective.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 65970] Tomcat cannot startup due to Stale PID

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65970

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

--- Comment #4 from Mark Thomas <ma...@apache.org> ---
Moving this to an enhancement request.

As Konstantin pointed out, the pid file should be in "/run" (or "/var/run") and
then it won't be present after a reboot (if it is then that would be an OS
issue to take up with your OS vendor).

I am not in favour of adding a whole lot of plumbing to the Tomcat scripts to
handle a non-standard use case. Users that want to do that can put that
plumbing in setenv.sh.

I agree with Konstantin that we should review the docs to make sure that the
correct usage is recommended and also that WONTFIX is the most likely
resolution for this issue.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 65970] Tomcat cannot startup due to Stale PID

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65970

Christopher Schultz <ch...@christopherschultz.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All

--- Comment #1 from Christopher Schultz <ch...@christopherschultz.net> ---
This situation was probably caused by a very unusual circumstance, such as a
power failure or kill-9 signal.

It's not clear what you are asking for, here. If CATALINA_PID exists and there
is an existing process matching that PID, then Tomcat will not start because it
looks like Tomcat is already running.

With a low PID like that, it's probably a process that runs on startup, and,
with a stale PID file it's very likely to match another process that was
started on startup as well.

A better solution for you might be to place your PID file on volatile storage,
or somewhere the OS will clear-out upon reboot, like /tmp. Not all OSs
clear-out /tmp on reboot, but some of them do. Another option would be to
instruct your init system to delete certain files (including the Tomcat PID
file) early-on in the boot process to make sure the PID file just doesn't exist
at all.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 65970] Tomcat cannot startup due to Stale PID

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65970

--- Comment #2 from Konstantin Kolinko <kn...@gmail.com> ---
(In reply to Christopher Schultz from comment #1)
> A better solution for you might be to place your PID file on volatile
> storage, or somewhere the OS will clear-out upon reboot, like /tmp.

+1

The current Filesystem Hierarchy Standard (FHS) 3.0 says that there is the
"/run/" directory for this purpose.

(I am used to an older variant of that, "/var/run/", which is now obsoleted).

References from FHS 3.0:

https://refspecs.linuxfoundation.org/FHS_3.0/fhs.html#runRuntimeVariableData
3.15. /run : Run-time variable data

https://refspecs.linuxfoundation.org/FHS_3.0/fhs.html#varrunRuntimeVariableData
5.13. /var/run : Run-time variable data

BTW, Wikipedia:
https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard


A good place to set your value for CATALINA_PID environment variable is a
setenv.sh file ($CATALINA_BASE/bin/setenv.sh), as documented in RUNNING.txt.


I think this issue is going to be closed as WONTFIX. Maybe some docs need an
improvement?

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 65970] Tomcat cannot startup due to Stale PID

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65970

--- Comment #5 from Christopher Schultz <ch...@christopherschultz.net> ---
(In reply to eddie.wu from comment #3)
> exactly I am talking about the case of power failure or kill-9 signal.
> basically in such scenario, current scrip code will treat the stale PID
> (which is generated before VM reboot) as current running tomcat process and
> hence refuse to start Tomcat.

This is only true if the PID file contains the PID of a currently-running
process. If you stop Tomcat, start it again, then do a kill -9 on the process
and try to restart it, I suspect you'll see a message in the logs about
clearing-away a (truly) stale PID file. On startup, however, there are many
processes with small PIDs which may coincidentally overlap with the one in the
PID file.

> My expectation is that Tomcat script to ignore this stale PID and go ahead
> to startup. And I propose to compare the time stamp of $CATALINA_PID file
> and the time when reboot happened to judge whether it is a STALE PID.

File timestamps can be misleading or wrong.

I would prefer better interrogation of the PID which is currently running to
see if it seems likely to be an actual Tomcat process. For example, if the
command-line string for that process includes catalina.base=${CATALINA_BASE}
then it's the correct one. If it doesn't contain that string, then it's very
unlikely to be an actual Tomcat launched using this same technique (i.e.
bin/catalina.sh).

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 65970] Tomcat cannot startup due to Stale PID

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65970

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |WONTFIX
             Status|NEW                         |RESOLVED

--- Comment #6 from Mark Thomas <ma...@apache.org> ---
There was only one mention of a specific location for CATALINA_PID in the docs
in RUNNING.txt and I have updated that to use /run

As per previous comments, I'm resolving this as WONTFIX.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org