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

 

posted @ 2019-06-03 14:30  James-Y-G-Yin  阅读(695)  评论(0编辑  收藏