**环境准备
准备一台Centos7服务器
系统: Centos7.3
内存:1G
cpu: 2核
IP地址: 10.0.0.41**
vim jk_httpd.sh
#!/bin/bash
while true
do
port_num=$(ss -ntl | grep -c 80)
if [ $port_num -eq 0 ];then
echo "httpd服务已经停止运行!"
/usr/local/sbin/mail.py 1052802235@qq.com "警告! ! " "httpd服务已经停止运行! "
num=1
while [ $num -le 30 ]
do
sleep 2
port_num=$(ss -ntl | grep -c 80)
if [ $port_num -eq 1 ];then
echo "httpd服务恢复! "
/usr/local/sbin/mail.py 1052802235@qq.com "恢复 " "httpd服务已经恢复运行! "
break
fi
let num++
done
fi
sleep 5
done
sh jk_httpd.sh
# 停止阿帕奇服务
systemctl stop httpd
# 启动阿帕奇服务
systemctl start httpd