- #!/bin/bash
- echo "重启[api]!"
- /www/server/panel/pyenv/bin/supervisorctl restart api:api_00
- # curl http://127.0.0.1:7001/
- echo "验证[api]!"
- #设置变量,url为你需要检测的目标网站的网址(IP或域名)
- url=http://127.0.0.1:7002/
- declare -i status_code=-1
-
- #定义函数check_http:
- #使用curl命令检查http服务器的状态
- #-m设置curl不管访问成功或失败,最大消耗的时间为5秒,5秒连接服务为相应则视为无法连接
- #-s设置静默连接,不显示连接时的连接速度、时间消耗等信息
- #-o将curl下载的页面内容导出到/dev/null(默认会在屏幕显示页面内容)
- #-w设置curl命令需要显示的内容%{http_code},指定curl返回服务器的状态码
- check_http(){
- status_code=$(curl -m 5 -s -o /dev/null -w %{http_code} $url)
- }
-
- while :
- do
- check_http
-
- # date=$(date +%Y%m%d-%H:%M:%S)
-
- if [ $status_code -ne 200 ];then
- echo "$url $status_code !"
- # mail -s Warning root < /tmp/http$.pid
- else
- echo "$url $status_code 启动成功 ^_^"
- break
- fi
- sleep 1
- done
复制代码
|
|