zoukankan      html  css  js  c++  java
  • nginx启动脚本

    #!/bin/bash
    
    CURRDIR=`dirname "$0"`
    BASEDIR=`cd "$CURRDIR"; pwd`
    
    NAME="nginx"
    CMD=/usr/local/nginx/sbin/nginx
    
    if [ "$1" = "-d" ]; then
        shift
        EXECUTEDIR=$1'/'
        shift
    else
        EXECUTEDIR=$BASEDIR'/'
    fi
    
    if [ ! -d "$EXECUTEDIR" ]; then
        echo "ERROR: $EXECUTEDIR is not a dir"
        exit
    fi
    
    if [ ! -d "$EXECUTEDIR"/conf ]; then
        echo "ERROR: could not find $EXECUTEDIR/conf/"
        exit
    fi
    
    if [ ! -d "$EXECUTEDIR"/logs ]; then
        mkdir "$EXECUTEDIR"/logs
    fi
    
    cd "$EXECUTEDIR"
    PID_FILE="$EXECUTEDIR"/logs/nginx.pd
    
    check_pid() {
        RETVAL=1
        if [ -f $PID_FILE ]; then
            PID=`cat $PID_FILE`
            ls /proc/$PID &> /dev/null
            if [ $? -eq 0 ]; then
                RETVAL=0
            fi
        fi
    }
    
    check_running() {
        PID=0
        RETVAL=0
        check_pid
        if [ $RETVAL -eq 0 ]; then
            echo "$CMD is running as $PID, we'll do nothing"
            exit
        fi
    }
    
    start() {
        check_running
        #echo "$CMD -c $EXECUTEDIR/conf/nginx.conf -p $EXECUTEDIR"
        "$CMD" -c "$EXECUTEDIR/conf/nginx.conf" -p "$EXECUTEDIR"
    }
    
    stop() {
        "$CMD" -c "$EXECUTEDIR/conf/nginx.conf" -p "$EXECUTEDIR" -s stop
    }
    
    status() {
        check_pid
        if [ $RETVAL -eq 0 ]; then
            echo "nginx is running as $PID ..."
        else
            echo "nginx is not running"
        fi
    }
    
    reload() {
        "$CMD" -c "$EXECUTEDIR/conf/nginx.conf" -p "$EXECUTEDIR" -t
        if [ $? -ne 0 ]; then
            echo "test nginx conf fail. please check it first, we won't reload it"
            exit 1
        fi
        "$CMD" -c "$EXECUTEDIR/conf/nginx.conf" -p "$EXECUTEDIR" -s reload
    }
    
    RETVAL=0
    case "$1" in
        start)
            start
            ;;
        stop)
            stop
            ;;
        restart)
            stop
            start
            ;;
        status)
            status
            ;;
        reload)
            reload
            ;;
        *)
        echo "Usage: $0 {start|stop|restart|status|reload}"
        RETVAL=1
    esac
    exit $RETVAL
  • 相关阅读:
    关于此主题 v1
    从博客园主题了解前端 CSS
    VS2019 许可证到期
    从博客园主题了解前端 HTML
    关于此主题
    从博客园主题了解前端 JS
    GCC 编译器
    Python的Set和List的性能比较 + 两者之间的转换
    wsgi初探(转)
    权限设计概要
  • 原文地址:https://www.cnblogs.com/JahanGu/p/7744146.html
Copyright © 2011-2022 走看看