shell学习之十八--nginx启动脚本(if)
来源:互联网 发布:淘宝卖lol限定皮肤 编辑:程序博客网 时间:2024/06/05 10: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 $() {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
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
阅读全文
0 0
- shell学习之十八--nginx启动脚本(if)
- shell脚本学习之if..else用法
- shell学习二十一--使用if编写mysql启动脚本
- linux shell脚本之if
- shell 脚本之if判断
- shell脚本之if语句
- shell学习之 if
- shell学习二十八--centos7初始化脚本
- 脚本学习-----常用shell脚本if参数
- Shell脚本基础学习(三)----if-then控制
- shell脚本里的if语句学习
- linux shell脚本之if判断
- linux shell 脚本之【2】if详解
- SHELL脚本分支结构之if
- Linux shell脚本之 if条件判断
- [Linux] shell脚本之if判断
- 【shell编程】 nginx 服务的启动脚本
- shell脚本之条件语句if和分支语句case...esac【shell脚本的学习笔记三】
- mybatis级联
- sqoop could not load db driver class:oracle.jdbc.OracleDriver
- 徐登沿的第十个程序(计数控制的循环)
- PHP 基础总结
- 个人理解(非)阻塞与同步异步
- shell学习之十八--nginx启动脚本(if)
- vuex
- 数据结构|专业学习思维
- java读取properties配置文件的几种方式
- 79. Word Search
- 基于SQLite的安卓平台用户信息管理系统
- SpringMvc之值(View到Controller)的传递-yellowcong
- Unity3D更改游戏鼠标样式
- 数据库建表方法