神剑山庄资源网 Design By www.hcban.com
说明下:我的主机为 Centos 系统,各步操作的说明都写在了注释里面,方便阅读。
vi apachemonitor.sh #!/bin/bash URL=”http://127.0.0.1/” curlit() { curl –connect-timeout 15 –max-time 20 –head –silent “$URL” | grep '200′ # 上面的15是连接超时时间,若访问localhost的HTTP服务超过15s仍然没有正确响应200头代码,则判断为无法访问。 } doit() { if ! curlit; then # 如果localhost的apache服务没有正常返回200头,即出现异常。执行下述命令: sleep 20 top -n 1 -b /var/log/apachemonitor.log # 上面将top命令内容写入日至文件备查 /usr/bin/killall -9 apache2 && /usr/bin/killall -9 php5-cgi && /usr/bin/killall -9 httpd && /usr/bin/killall -9 http && /usr/bin/killall -9 apache && /usr/bin/killall -9 php-cgi > /dev/null # 兼容起见,杀死了各种apache的进程。可以根据自己apache服务的特点修改 sleep 2 /etc/init.d/apache2 start > /dev/null /etc/init.d/httpd start > /dev/null # 兼容起见,执行了两种apache重启命令,可根据需要自己修改。 echo $(date) “Apache Restart” /var/log/apachemonitor.log # 写入日志 sleep 30 # 重启完成后等待三十秒,然后再次尝试一次 if ! curlit; then # 如果仍然无法访问,则: echo $(date) “Failed! Now Reboot Computer!” /var/log/apachemonitor.log # 写入apache依然重启失效的日志 reboot # 重启机器呗。实际上重启整个服务器是一种非常不得已的做法。本人并不建议。大家根据需要自己修改,比如短信、邮件报警什么的。 fi sleep 180 fi } sleep 300 # 运行脚本后5分钟后才开始正式工作(防止重启服务器后由于apache还没开始启动造 成误判) while true; do # 主循环体 doit > /dev/null sleep 10 done 然后执行: chmod +x apachemonitor.sh 添加开机启动项: vi /etc/rc.d/rc.local 我的rc.local脚本内容为: #!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff. touch /var/lock/subsys/local /root/lampmonitor.sh
标签:
重启,Apache
神剑山庄资源网 Design By www.hcban.com
神剑山庄资源网
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
神剑山庄资源网 Design By www.hcban.com
暂无Linux下一个智能重启Apache服务器的脚本分享的评论...
更新日志
2024年09月20日
2024年09月20日
- 魏新雨《为你祈祷+新歌精逊2CD[WAV]
- 影心、明萨拉你选哪个?国外美女COS《博德3》
- 澳洲女子骑车跌入“自杀树”丛 疼痛持续9个月崩溃
- 育碧公布2024“她创力”计划:为女性游戏人提供辅导
- 刘美君.2017-千色·30总选3CD【环球】【WAV+CUE】
- 群星.2022-星河长明电视原声带【乐有奇思】【FLAC分轨】
- 陈淑桦.1995-淑桦盛开Forever【滚石】【WAV+CUE】
- 《再来一张》评测:出师成败皆系“赌”
- 《银河汉堡店》测评:我是银河走菜王!
- 萧煌奇《没事的》[320K/MP3][96.22MB]
- 萧煌奇《没事的》[FLAC/分轨][263.38MB]
- 群星《音你而来 第6期》[320K/MP3][90.61MB]
- 交错战线爬塔攻略一览
- 战锤40K星际战士2全近战武器使用教学|近战武器连招表
- 交错战线暴力队配队阵容一览