加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 09:17:45 所属栏目:安全 来源:网络整理
导读:一、安装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 $() {s
一、安装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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读