一、安装
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 原文链接:https://www.f2er.com/bash/389734.html