-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Rafael,
On 4/23/20 17:18, Rafael Oliveira wrote: > I does not happen every time, but it happens, actually it happened > twice during a couple of deployments and only in one instance of > several that I have. > > I could not reproduce in a safe and close environment, I got this > error in a server with multiple users and multiple tasks and > concurred environment. > > The point is raise a question is this echo $! > "CATALINA_PID" the > best approach to get the PID? It's literally the only way to do it. $! doesn't get you the PID of some random other process that was recently started. It's exactly what it says it is: the PID of the last process that was backgrounded by the currently-executing script. If your pid-file contains the wrong PID, it's probably because something overwrite overwrote it after it was initially-generated. If you try to start Tomcat twice, for example, like this: $ CATALINA_HOME/bin/startup.sh [...] $ cat $CATALINA_PID 1234 $ CATALINA_HOME/bin/startup.sh [...] $ cat $CATALINA_PID 2345 $ ps -ef | grep "catalina.base=$CATALINA_HOME" 1234 The startup script will always overwrite the PID file because it can't tell if it's going to fail (which it will, since the shutdown port is already bound to the first-launched instance). In the case above, the PID-file is clobbered by the second process while the first process continues to run (and be the correct process id). There isn't much to be done about that without resorting to drastic measures, such as having Tomcat write its own PID file after it starts up (enough), and getting the PID from Java isn't super-straightforward until Java 9. :( - -chris > Em qui., 23 de abr. de 2020 às 02:44, calder > <calder....@gmail.com> escreveu: > >> On Wed, Apr 22, 2020 at 11:34 AM Rafael Oliveira >> <r.rolivei...@gmail.com> wrote: >>> Hello everyone during some tests where I ran in my local >>> environment I >> came >>> across an odd behavior on tomcat start >>> >>> During the start process catalina.sh script create a new PID >>> file using >> the >>> following statement *echo $! > "CATALINA_PID"* >>> >>> $! *Expands to the process **ID** of the job most recently >>> placed into >> the >>> background,* whether executed as an asynchronous command or >>> using the bg builtin >> >> Correct. >> >>> The PID number inside the PID file is different of the tomcat >>> process >> >> Not on my installations - using "./catalina.sh start > >> startup.txt 2>&1" >> >> user@stimpy:~/bin/apache-tomcat-9.0.26/bin> cat cat-pid 8732 >> user@stimpy:~/bin/apache-tomcat-9.0.26/bin> ps -aux | grep >> tomcat user 8732 1.3 0.2 23279772 161408 pts/1 Sl 00:28 >> 0:05 /usr/lib64/jvm/java/bin/java >> -Djava.util.logging.config.file=/home/user/bin/apache-tomcat-9.0.26/ >> >> >> ... and using "startup.sh" >> >> user@stimpy:~/bin/apache-tomcat-9.0.26/bin> cat cat-pid 9861 >> user@stimpy:~/bin/apache-tomcat-9.0.26/bin> ps -aux | grep >> tomcat user 9861 18.4 0.2 23277724 148168 pts/1 Sl 00:37 >> 0:04 /usr/lib64/jvm/java/bin/java >> -Djava.util.logging.config.file=/home/user/bin/apache-tomcat-9.0.26/ >> >>> >> started which I could verify with: >>> ps -ef | grep 'catalina.base=$CATALINA_HOME' >> >> ?? >> >> --------------------------------------------------------------------- >> >> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org >> For additional commands, e-mail: users-h...@tomcat.apache.org >> >> > -----BEGIN PGP SIGNATURE----- Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/ iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl6iThsACgkQHPApP6U8 pFjhHBAAiO2x2N360ZE93w7e6OOYGG/fhyJJELiSkRuL5EQ0nmuK4ogFNvA6elQi 9Es1piIs7u5/AaSR/1eUcpoSGCCJAPHBC1oFyl9n4mWuL1+uKjGfGIPH2y3v8UEo SNJXSZHU3EG9jLPp+txY3oHO/ugDvjNowKlXn3wsrQxa2WS+zN4gruvGMWBg6D8u jdRv8avHfovIlTXGfyVj0N/4d5eUD25hw8/zekddntdjVt1B2G0eq8y29fy8uQQV Xkvzyer5ejzK+iE8PfMfn8cNHgmM0yG9ZCKdBDMijpq0PeDhtcsElHvSfx0FAlpr PPw/wQk3yZErBtNEm/ThiPPsT4v+Q6oir13hhbFEPiur1y9LlyFxYiQP4U95Vgmp UAHdSqjyl16QFn215j1Mfljjep7lKr21F9aOVgH8V3j5VD0FxXYzcJNrItW4uRx4 jik9IuCD/z8IHTq10eI+G+peeCKt9t64byYZVphNq4gIWjrjFr3ZVitFuqGEzqqc wipKgrmf+iRidygEubak3JhM/0Go4YdkVCDFcoT56XYYs27XTUYeDGBAvL/uo7/O /vkIGiHxv0f5+N2OlI9Hv5j04m02CKRTiZMvDdS72u6dT2sGdKuhZbLR8eRs1ZAD X9uhJ7jCkuHFgPRC5p5IZMNOl6qn7RGIyZUT+NGoaMpbTaaRcJ4= =xf+8 -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org