shell脚本之nginx自动化脚本
今天小编就为大家分享一篇关于shell脚本之nginx自动化脚本,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
这个脚本,可以满足nginx开启,停止和重启的操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #!/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~
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值