shell学习之十八--nginx启动脚本(if)

前端之家收集整理的这篇文章主要介绍了shell学习之十八--nginx启动脚本(if)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
一、安装Nginx http://blog.csdn.net/yujin2010good/article/details/51637912 二、编写脚本(使用if编写Nginx启动脚本) 1、编写初步脚本 [root@node01 day7]# vi Nginx_stat.sh #!/bin/sh . /etc/init.d/functions if [ $# -ne 1 ] then echo "USAGE $() {start|stop|restart}" exit 1 fi if [ "$1" == "start" ] then action "start Nginx" /bin/true elif [ "$1" == "stop" ] then action "stop Nginx" /bin/true elif [ "$1" == "restart" ] then action "restart Nginx" /bin/true else echo "USAGE $() {start|stop|restart}" exit 1 fi [root@node01 day7]# sh Nginx_stat.sh start start Nginx [ OK ] [root@node01 day7]# sh Nginx_stat.sh stop stop Nginx [ OK ] [root@node01 day7]# sh Nginx_stat.sh start start Nginx [ OK ] [root@node01 day7]# sh Nginx_stat.sh USAGE {start|stop|restart} [root@node01 day7]# 2、优化脚本(代入函数) #!/bin/sh . /etc/init.d/functions USAGE(){ echo "USAGE $() {start|stop|restart}" exit 1 } if [ $# -ne 1 ] then USAGE fi if [ "$1" == "start" ] then action "start Nginx" /bin/true elif [ "$1" == "stop" ] then action "stop Nginx" /bin/true elif [ "$1" == "restart" ] then action "restart Nginx" /bin/true else USAGE fi [root@node01 day7]# sh Nginx_stat02.sh USAGE {start|stop|restart} [root@node01 day7]# sh Nginx_stat02.sh start start Nginx [ OK ] [root@node01 day7]# sh Nginx_stat02.sh stop stop Nginx [ OK ] [root@node01 day7]# sh Nginx_stat02.sh restart restart Nginx [ OK ] [root@node01 day7]# sh Nginx_stat02.sh restart fd kjk 121 USAGE {start|stop|restart} 3、加入真正操作 #!/bin/sh . /etc/init.d/functions start_Nginx=/soft/Nginx-1.8.1/objs/Nginx USAGE(){ echo "USAGE $() {start|stop|restart}" exit 1 } if [ $# -ne 1 ] then USAGE fi if [ "$1" == "start" ] then $start_Nginx action "start Nginx" /bin/true elif [ "$1" == "stop" ] then killall Nginx action "stop Nginx" /bin/true elif [ "$1" == "restart" ] then pkill Nginx sleep 2 $start_Nginx action "restart Nginx" /bin/true else USAGE fi [root@node01 day7]# sh Nginx_start03.sh start start Nginx [ OK ] [root@node01 day7]# ps -ef |grep Nginx root 73948 1 0 23:33 ? 00:00:00 Nginx: master process /soft/Nginx-1.8.1/objs/Nginx Nginx 73950 73948 0 23:33 ? 00:00:00 Nginx: worker process root 73952 56270 0 23:33 pts/4 00:00:00 grep Nginx [root@node01 day7]# sh Nginx_start03.sh restart restart Nginx [ OK ] [root@node01 day7]# sh Nginx_start03.sh stop stop Nginx [ OK ] [root@node01 day7]# ps -ef |grep Nginx root 74026 56270 0 23:34 pts/4 00:00:00 grep Nginx [root@node01 day7]# ps -ef |grep Nginx root 74028 56270 0 23:34 pts/4 00:00:00 grep Nginx

猜你在找的Bash相关文章