linux :监控服务宕机和服务假死

主要是通过定时任务来判断服务状态

查看定时任务状态

 

2. 设定定时任务

 3.定时设置

[root@iZbp1hcc0n8gitu3a5ojz8Z james]# crontab -l
方式1:*/1 * * * * /home/xinlong/bin/james/monitor.sh >> /home/xinlong/bin/james/monitor.log
方式2:*/1 * * * * echo "hello">> /home/xinlong/bin/james/james1.log

 

 

#! /bin/sh

starttime=$(date +%Y-%m-%d\ %H:%M:%S)
hicode=$(curl -o /dev/null --retry 3 -s -w %{http_code} "http://10.132.66.204:8080")
if [ $hicode != "200" ] ;
then
echo "${starttime} server failed,code is : ${hicode}" #at here, wo can kill server thread, and then restart server.
else
echo "${starttime} server is fine! code is: ${hicode}" #no need to print log, in case of large log make cache down.
fi

 

转载于:https://www.cnblogs.com/zmjyyg/p/10967420.html

已标记关键词 清除标记
表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符 “速评一下”
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页