nginx 启动,停止,重载脚本

#!/bin/bash
nginx=/usr/local/nginx/sbin/nginx
read -ep "请输入 要执行的命令 (start|stop|reload|status):" asb
case $asb in
        # 启动nginx
        start)
        #检测nginx是否启动
        netstat -anpt |grep nginx &> /dev/null
        if [ $? -eq 0 ];then
                echo "nginx 已经启动"
        else
                echo "nginx 开始启动"
                echo "启动成功"
                $nginx
        fi
        ;;
        #停止nginx运行
        stop)
        netstat -anpt |grep nginx &> /dev/null
        if [ $? -eq 0 ];then
                $nginx -s stop
                echo "nginx 停止成功"
        else
                echo "nginx 已经停止"
        fi
        ;;
        #nginx状态信息
        status)
        netstat -anpt |grep nginx &> /dev/null
        if [ $? -eq 0 ];then
                echo "nginx 启动状态"
        else
                echo "nginx 没启动"
        fi

        ;;
        #重载nginx配置信息
        reload)
        netstat -anpt |grep nginx &> /dev/null
        if [ $? -eq 0 ];then
                $nginx -s reload
                echo " 重启nginx成功"
        else
                echo "nginx 重启失败,启动nginx"
                $nginx &> /dev/null
                netstat -anpt |grep nginx &> /dev/null
                if [ $? -eq 0 ];then
                        $nginx -s reload
                        echo " 重启nginx成功"
                else
                        echo "重启失败"
                fi

        fi

        ;;
        *)
        echo "输入有误!请按提示输入"
        ;;
esac
                                   
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值