0

Sometimes my tomcat server auto shutdown due to some memory issue, so I want to use the below script to check whether tomcat is running:

checkTomcatRunning.sh

TOMCAT_PID=$(ps -ef | awk '/[t]omcat/{print $2}')
echo TOMCAT PROCESSID $TOMCAT_PID

if [ -z "$TOMCAT_PID" ]
then
    echo "TOMCAT NOT RUNNING"
    sudo /opt/tomcat/bin/startup.sh
else
   echo "TOMCAT RUNNING"
fi

Below is the crontab which output log to /opt/tomcat/logs/checkTomcatRunning.log

crontab -l

*/1 * * * * /opt/tomcat/webapps/checkTomcatRunning.sh >>/opt/tomcat/logs/checkTomcatRunning.log 2>&1

in /opt/tomcat/logs/checkTomcatRunning.log, I can see 4 PID printed

cat /opt/tomcat/logs/checkTomcatRunning.log

TOMCAT PROCESSID 53585 53916 53917 53918
TOMCAT RUNNING

If run ps -ef | awk '/[t]omcat/{print $2}' from linux command line, there is only 1 PID 53585

ps -ef | awk '/[t]omcat/{print $2}'

53585

And I can only find 53585 in the running process, but not 53916 53917 53918.

ps -p 53585 53916 53917 53918

    PID TTY      STAT   TIME COMMAND
  53585 pts/0    Sl     0:50 /usr/bin/java -Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pk

Can anyone help to advise why there are 4 (but not 1) PIDs printed in checkTomcatRunning.log?

jiangwensi
  • 113
  • 2
  • 5

1 Answers1

0

Resolved by changing the path and name of the script and log file so that they don't contain "[t]omcat" keyword.

jiangwensi
  • 113
  • 2
  • 5