PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 服务器 > Linux教程 > 正文

    nginx服务挂掉自启动脚本

    作者:admin来源:网络浏览:时间:2021-02-23 18:28:43我要评论
    导读:#!/bin/bash# 加载环境变量source /etc/profile# nginx 和 resin 监听的端口号为 80 和 8080 ,检查 80 和 8080 端口是否有...
    #!/bin/bash

    # 加载环境变量
    source /etc/profile

    # nginx 和 resin 监听的端口号为 80 和 8080 ,检查 80 和 8080 端口是否有进程在监听
    port=`netstat -ntlp | grep -cE ":8080|:80"`
    #echo $port

    # 如果 80 或 8080 端口没有进程在监听
    if [ "$port" = "0" -o "$port" = "1" ]; then
        # 则重新启动 nginx 和 resin 的进程
        /usr/java/resin/bin/httpd.sh restart
        /etc/init.d/nginx restart

        # 将日志写入日志文件
        echo $(date "+%F %H:%M:%S") - already restart port - process not found >> /root/port.log
    # 如果 80 或 8080 端口有进程在监听
    else
        # 访问接口
        code=`curl http://127.0.0.1/check.jsp`

        # 如果返回的字符串不是 ok
        if [ "$code" != "ok" ]; then
            # 则重新启动 nginx 和 resin 的进程
            /usr/java/resin/bin/httpd.sh restart
            /etc/init.d/nginx restart

            # 将日志写入日志文件
            echo $(date "+%F %H:%M:%S") - already restart port - check fail ! >> /root/port.log
        fi
    fi



    或者使用monitor监控来实现服务器的自启动
    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-121-6504-1.html
    相关热词搜索: