Nginx安装启动shell脚本
作者:互联网
#!/bin/bash
ls /usr/local/nginx/sbin/nginx >/dev/null 2>&1
if [ $? != 0 ]
then
echo "没有发现源码版nginx,是否需要安装"
read -p "yes / no :" b
if [ $b = yes ]
then
echo "开始安装nginx源码包,请稍候"
sh nginxinstall.sh
else
echo "没有nginx程序,无法执行"
exit
fi
fi
start="/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf"
stop="kill `ps aux|grep nginx|grep master|awk '{print $2}'`"
echo "1=启动 2=停止 3=重启 4=查看运行"
read -p "请输入指令:" a
case $a in
1)
ps aux|grep nginx| grep master > /dev/null
if [ $? = 0 ]
then
echo "nginx 已经启动"
else
$start 2> /dev/null
ps aux|grep nginx| grep master > /dev/null
if [ $? = 0 ]
then
echo "nginx启动成功"
else
echo "nginx启动失败"
fi
fi
;;
2)
ps aux|grep nginx| grep master > /dev/null
if [ $? = 0 ]
then
$stop
ps aux|grep nginx| grep master > /dev/null
if [ $? = 0 ]
then
echo "nginx 关闭失败"
else
echo "nginx 关闭成功"
fi
else
echo "nginx 没有运行"
fi
;;
3)
ps aux|grep nginx| grep master > /dev/null
if [ $? = 0 ]
then
$stop
ps aux|grep nginx| grep master > /dev/null
if [ $? = 0 ]
then
echo "nginx 关闭失败"
else
echo "nginx 关闭成功"
fi
else
echo "nginx 没有运行"
fi
ps aux|grep nginx| grep master > /dev/null
if [ $? = 0 ]
then
echo "nginx 已经启动"
else
$start 2> /dev/null
ps aux|grep nginx| grep master > /dev/null
if [ $? = 0 ]
then
echo "nginx启动成功"
else
echo "nginx启动失败"
fi
fi
;;
4)
ps aux|grep nginx| grep master > /dev/null
if [ $? = 0 ]
then
echo "nginx 正在运行"
else
echo "nginx 没有运行"
fi
;;
*)
echo " 请输入 1 2 3 4"
;;
esac
标签:脚本,shell,grep,nginx,dev,Nginx,master,aux,nullif 来源: https://www.cnblogs.com/yhxcn/p/15189814.html