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 ] 
  • 相关阅读:
    区别@ControllerAdvice 和@RestControllerAdvice
    Cannot determine embedded database driver class for database type NONE
    使用HttpClient 发送 GET、POST、PUT、Delete请求及文件上传
    Markdown语法笔记
    Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
    Mysql 查看连接数,状态 最大并发数(赞)
    OncePerRequestFilter的作用
    java连接MySql数据库 zeroDateTimeBehavior
    Intellij IDEA 安装lombok及使用详解
    ps -ef |grep xxx 输出的具体含义
  • 原文地址:https://www.cnblogs.com/lexus/p/1826554.html
Copyright © 2011-2022 走看看