脚本说明
此脚本用于检测nginx是否运行,若没有运行,则可以选择启动或者重新加载,当然也有关闭功能
脚本源码
#!/bin/bash
nginx=/usr/local/nginx/sbin/nginx
read -ep "请输入要执行的命令(start/stop/status/reload):" sta
case sta in
#启动nginx选项
start)
#先检测nginx是否已经启动
netstat -nlpt | grep nginx &> /dev/null
if [? -eq 0 ];then
echo "nginx已经启动!"
else
echo "开始启动nginx!"
nginx
fi
;;
#停止nginx运行
stop)nginx -s stop
#判断nginx是否已经停止
if [ ? -eq 0 ];then
echo "nginx已经停止运行!"
else
echo "nginx停止失败,请重试!"
fi
;;
#nginx的状态
status)
netstat -nlpt | grep nginx &> /dev/null
if [? -eq 0 ];then
echo "nginx已经启动!"
else
echo "nginx没有运行!"
fi
;;
#重载nginx
reload)
nginx -s reload
if [? -eq 0 ];then
echo "nginx重载成功!"
else
echo "nginx重载失败,请重试!"
fi
;;
*)
echo "请按提示正确输入!"
;;
esac
本文链接:http://www.geekyunwei.com/1127.html
网友评论comments