ServerName=(bam bcc bpcplatform bpccenter)
BimID=$(ps -ef |grep "bam"|grep -v 'grep' |awk '{printf $2}')
BCCID=$(ps -ef |grep "bim-configuration"|grep -v 'grep' |awk '{printf $2}')
BPCPlatformID=$(ps -ef | grep "home/bpc/apache-tomcat-8.0.53" | grep -v grep | awk '{print $2}')
BPCCenterID=$(ps -ef | grep "/bpc/app-center/" | grep -v grep | awk '{print $2}')
IDS=($BimID $BCCID $BPCPlatformID $BPCCenterID)
StartBim=/usr/local/tomcat/apache-tomcat-8.0.53/bin/startup.sh
BimCache=/usr/local/tomcat/apache-tomcat-8.0.53/work
StartBCC=/app/home/bcc/nohup-run.sh
BCCCache=/app/home/bcc/\*.gz
StartBPCPlatform=/app/home/bpc/apache-tomcat-8.0.53/bin/startup.sh
BPCPlatformCache=/app/home/bpc/apache-tomcat-8.0.53/work
StartBPCCenter=/app/home/bpc/app-center/tomcat-center/bin/startup.sh
BPCCenterCache=/app/home/bpc/app-center/tomcat-center/work
Starts=($StartBim $StartBCC $StartBPCPlatform $StartBPCCenter)
Caches=($BimCache $BCCCache $BPCPlatformCache $BPCCenterCache)
BimWebUrl=http://172.16.20.51:8083/business-ui/login
BCCWebUrl=http://172.16.20.51:8021
BPCPlatformWebUrl=http://172.16.20.51:8015
BPCCenterWebUrl=http://172.16.20.51:8035
WebUrl=($BimWebUrl $BCCWebUrl $BPCPlatformWebUrl $BPCCenterWebUrl)
BimGetPageInfo=/tmp/BimMonitor.Info
BimMontorLog=/tmp/BimMonitor.log
BCCGetPageInfo=/tmp/BCCMonitor.Info
BCCMontorLog=/tmp/BCCMonitor.log
BPCPlatformGetPageInfo=/tmp/BPCPlatformMonitor.Info
BPCPlatformMontorLog=/tmp/BPCPlatformMonitor.log
BPCCenterGetPageInfo=/tmp/BPCCenterMonitor.Info
BPCCenterMontorLog=/tmp/BPCCenterMonitor.log
GetPageInfo=($BimGetPageInfo $BCCGetPageInfo $BPCPlatformGetPageInfo $BPCCenterGetPageInfo)
MontorLog=($BimMontorLog $BCCMontorLog $BPCPlatformMontorLog $BPCCenterMontorLog)
Monitor()
{
echo "[info]开始监控${ServerName[$i]}...[$(date +'%F %H:%M:%S')]"
if [ "${IDS[$i]}" ];then
echo "[info]当前${ServerName[$i]}进程ID为:${IDS[$i]},继续检测页面..."
ServiceCode=$(curl -s -o ${GetPageInfo[$i]} -m 10 --connect-timeout 10 ${WebUrl[$i]} -w %{http_code})
if [ $ServiceCode -eq 200 ];then
echo "[info]页面返回码为$ServiceCode,${ServerName[i]}启动成功,测试页面正常"
else
echo "[error]${ServerName[$i]}页面出错,请注意...状态码为$ServiceCode,错误日志已输出到${GetPageInfo[$i]}"
echo "[error]页面访问出错,开始重启${ServerName[$i]}"
kill -9 ${IDS[$i]}
if [ ${ServerName[$i]} = "bam" ];then
sleep 600
else
sleep 3
fi
rm -rf ${Caches[$i]}
${Starts[i]}
fi
else
echo "[error]${ServerName[$i]}进程不存在!${ServerName[$i]}开始自动重启..."
echo "[info]${Starts[$i]},请稍候..."
rm -rf ${Caches[$i]}
${Starts[$i]}
fi
echo "--------------------------"
}
i=0
while(( $i < 4 ))
do
Monitor
let "i++"
done
|