失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > nginx linux脚本 shell脚本之nginx自动化脚本

nginx linux脚本 shell脚本之nginx自动化脚本

时间:2023-08-26 13:19:12

相关推荐

nginx linux脚本 shell脚本之nginx自动化脚本

这个脚本,可以满足nginx开启,停止和重启的操作

#!/bin/bash

. /etc/init.d/functions

function usage() {

echo $"usage:$0 {start|stop|restart}"

exit 1

}

function start() {

/usr/local/nginx/sbin/nginx

sleep 1

if [ `netstat -antlpe | grep nginx | wc -l` -ge 0 ];then

action "nginx is started." /bin/true

else

action "nginx is started." /bin/false

fi

}

function stop() {

killall nginx &>/dev/null

sleep 1

if [ `netstat -antlpe | grep nginx | wc -l` -eq 0 ];then

action "nginx is stopped." /bin/true

else

action "nginx is stopped." /bin/false

fi

}

function main() {

if [ $# -ne 1 ];then

usage $0

fi

case $1 in

start)

start

;;

stop)

stop

;;

restart)

stop

start

;;

*)

usage $0

;;

esac

}

main $*

运行试试

1.停止nginx

2.开启nginx

3.重启nginx

ok~

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对脚本之家的支持。如果你想了解更多相关内容请查看下面相关链接

如果觉得《nginx linux脚本 shell脚本之nginx自动化脚本》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。