0
点赞
收藏
分享

微信扫一扫

74、75、76——tomcat项目实战

吃面多放酱 2023-08-11 阅读 8

编写脚本

tomcatMonitor.sh

#!/bin/sh

. /etc/profile
. ~/.bash_profile


#首先用ps -ef | grep tomcat 获得了tomcat进程信息,这样出来的结果中会包含grep本身,
#因此通过 | grep -v grep 来排除grep本身,然后通过 awk '{print $2}'来打印出要找的进程id号;
pid=$(ps -ef|grep apache-tomcat-8.5.47 |grep -v grep | awk '{print $2}') 
#echo $pid

if [ -n "$pid" ];then  
    echo "tomcat进程ID为:$pid. 运行正常" 
else  
  echo "进程不存在! Tomcat自动重启"  
  cd /usr/local/apache-tomcat-8.5.47/bin/ &&  ./startup.sh
fi 

为脚本添加可执行权限

chmod u+x tomcatMonitor.sh

配置定时任务

*/30 * * * * /usr/local/tomcatMonitor.sh

重启定时任务:systemctl start crond

举报

相关推荐

0 条评论