Nginx教程

Nginx安装启动shell脚本

本文主要是介绍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

这篇关于Nginx安装启动shell脚本的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!