A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 柠檬leung不酸 黑马粉丝团   /  2019-1-15 16:57  /  1091 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

这个脚本,可以满足nginx开启,停止和重启的操作

#!/bin/bash
. /etc/init.d/functions

function usage() {
    echo $"usage:$0 {start|stop|restart}"
    exit 1
}

function start() {
    /usr/local/nginx/sbin/nginx
    sleep 1
    if [ `netstat -antlpe | grep nginx | wc -l` -ge 0 ];then
        action "nginx is started." /bin/true
    else
        action "nginx is started." /bin/false
    fi
}

function stop() {
    killall nginx &>/dev/null
    sleep 1
    if [ `netstat -antlpe | grep nginx | wc -l` -eq 0 ];then
        action "nginx is stopped." /bin/true
    else
        action "nginx is stopped." /bin/false
    fi
}

function main() {
    if [ $# -ne 1 ];then
        usage $0
    fi
    case $1 in
        start)
        start
        ;;
        stop)
        stop
        ;;
        restart)
        stop
        start
        ;;
        *)
        usage $0
        ;;
    esac
}

main $*
运行试试

1.停止nginx



2.开启nginx



3.重启nginx



ok~
---------------------
作者:Mr.o.j
来源:CSDN
原文:https://blog.csdn.net/weixin_40543283/article/details/85948002


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马