侧边栏壁纸
博主头像
七哥的技术博客

You got a dream, you gotta to protect it!

  • 累计撰写 85 篇文章
  • 累计创建 76 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

服务器增加健康监控检查

admin
2025-02-15 / 0 评论 / 0 点赞 / 12 阅读 / 0 字

以部署 halo 为例,增加 start、stop、restart、monitor 脚本,并且 crontab 增加定时检查

start.sh 脚本

#!/bin/bash

SHELL=/bin/bash

nohup java -Dfile.encoding=UTF-8 -jar halo.jar --spring.config.additional-location=optional:file:/root/halo/ --debug >/dev/null 2>&1 & 

stop.sh 脚本

#!/bin/bash

SHELL=/bin/bash

ps aux | grep halo | grep -v grep | awk '{print $2}' | xargs -r kill -9

restart.sh 脚本

#!/bin/bash

SHELL=/bin/bash

echo "restart app, now stop ..."
./stop.sh

sleep 1

echo "restart app, now start ..."
./start.sh

monitor.sh 脚本

#!/bin/bash

SHELL=/bin/bash

cnt=`ps -ef|grep halo|grep -v grep|grep -v monitor|grep -v log|wc -l`
echo `date`"   cnt:$cnt"

if [ "$cnt" == "0" ]; then
    echo "check is unnormal ..."
    cd /root/halo/ && ./restart.sh 
fi

find /root/halo/logs/ -mtime +7 -exec rm -rf {} \;

crontab 增加定时任务

* * * * * /root/halo/monitor.sh >> /root/halo/monitor.log 
0

评论区