寻找正在运行的tomcat进程ID的问题 [英] Problem on looking for running tomcat process id

查看:67
本文介绍了寻找正在运行的tomcat进程ID的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时由于内存问题,我的tomcat服务器自动关闭,因此我想使用以下脚本检查tomcat是否正在运行:

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:

检查TomcatRunning.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

下面是crontab,它将日志输出到/opt/tomcat/logs/checkTomcatRunning.log

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

crontab -l <​​/strong>

crontab -l

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

在/opt/tomcat/logs/checkTomcatRunning.log中,我可以看到打印了4个PID

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

如果运行ps -ef |从Linux命令行awk'/[t] omcat/{print $ 2}',只有1个PID 53585

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

在运行过程中,我只能找到53585,而在运行过程中找不到53916 53917 53918.

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

任何人都可以帮助建议为什么在checkTomcatRunning.log中打印4个(但不是1个)PID吗?

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

推荐答案

通过更改脚本和日志文件的路径和名称以使它们不包含"[t] omcat"来解决.关键字.

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

这篇关于寻找正在运行的tomcat进程ID的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆