tomcat心跳脚本--(配合keepalived)
#!/bin/bash
#
#********************************************************************
#Author: nwq
#QQ: 3078499367
#Date: 2024-07-22
#FileName: tomcat_check.sh
#URL: http://www.sansi.fun
#Description: The test script
#Copyright (C): 2024 All rights reserved
#********************************************************************
# 定义Tomcat进程检查命令,这里通过查找特定目录下的Java进程来判断Tomcat是否运行
tomcat_pid=$(pgrep -f "/apps/tomcat1/bin/bootstrap.jar")
# 检查Tomcat是否在运行
if [ -z "$tomcat_pid" ]; then
echo "Tomcat is not running. Stopping keepalived service..."
# 停止keepalived服务
systemctl stop keepalived
else
echo "Tomcat is running with PID: $tomcat_pid"
fi