#!/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
nginx 启动,停止,重载脚本
最新推荐文章于 2021-05-15 01:28:30 发布