# chkconfig: 2345 99 20<br>2345表示系统运行级别是2,3,4或者5时都启动此服务,<br>99,是启动的优先级,<br>20, 是关闭的优先级
#description: nginx-server
#!/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)
netstat -nlpt | grep nginx &> /dev/null
#判断nginx是否已经停止
if [ $? -eq 0 ];then
$nginx -s stop
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)
netstat -nlpt | grep nginx &> /dev/null
if [ $? -eq 0 ];then
$nginx -s reload
echo "nginx重载成功!"
else
echo "nginx重载失败,请先启动nginx!"
fi
;;
*)
echo "请按提示正确输入!"
;;
esac