zoukankan      html  css  js  c++  java
  • Nginx 遇到 502 Bad Gateway 自动重启脚本

    放到crontab里一分钟执行一次。url和cmd根据自己的改。
    原理就是用curl获取HTTP头,发现502状态码就执行重启php-fpm的命令。

    <span style="color: #666666; font-style: italic;">#!/usr/bin/php
    </span><span style="color: #339933;"><!--</span><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.deepvps.com'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/usr/local/php/sbin/php-fpm restart'</span><span style="color: #339933;">;</span>
     
    <span style="color: #b1b100;">for</span><span style="color: #009900;">(</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;"><</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">++</span><span style="color: #009900;">)</span><span style="color: #009900;">{</span>         <span style="color: #000088;">$exec</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">"curl  connect-timeout 3 -I <span style="color: #006699; font-weight: bold;">$url</span> 2>/dev/null"</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #990000;">shell_exec</span><span style="color: #009900;">(</span><span style="color: #000088;">$exec</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
     
            <span style="color: #b1b100;">if</span><span style="color: #009900;">(</span><span style="color: #990000;">stripos</span><span style="color: #009900;">(</span><span style="color: #000088;">$res</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'502 Bad Gateway'</span><span style="color: #009900;">)</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">)</span><span style="color: #009900;">{</span>
                    <span style="color: #990000;">shell_exec</span><span style="color: #009900;">(</span><span style="color: #000088;">$cmd</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
                    <span style="color: #990000;">exit</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">}</span>
    <span style="color: #009900;">}</span>
    <span style="color: #339933;">--></span>

    至于crontab,请自行Google搜索

    转自:http://www.hostloc.com/viewthread.php?tid=19208&page=1#pid235729

    原创文章如转载,请注明:转载自深度VPS [ http://www.deepvps.com ] 
  • 相关阅读:
    ElasticSearch 之 Client
    Ubuntu 更新源
    ThinkPad 禁用 触摸板
    编译OpenGL代码时发生 Inconsistency detected by ld.so: dl-version.c: 224: _dl_check_map_versions: Assertion `needed != ((void *)0)' failed! 错误的解决方案
    python 自动认证登录
    RIDE的使用
    robotframework的分支和循环
    webdriver入门
    python字符串中的中文处理
    带认证的页面的自动认证登录
  • 原文地址:https://www.cnblogs.com/lexus/p/1826554.html
Copyright © 2011-2022 走看看