用shell编写nginx脚本的启动,关闭,重加载
2017-08-12 16:04
232 查看
#!/bin/bash ----默认执行shell方式 #chkconfig: 2345 10 80 ----加入到开机执行的方式 path="/usr/local/nginx/sbin/nginx" ----源代码安装nginx之后的启动路径 name="nginxd" test=0 log=/tmp/nginxd.log ----nginx的日志 DATE=`date "+%F %H:%M:%S"` ----获得系统时间命令 #判断nginx是否已经安装或者判断源码安装之后启动的路径是否存在。 if [ ! -x $path ];then echo -n "${path} not installed!" exit 10 fi #启动选项,对执行nginx进行启动,启动成功或者失败都会输出提醒。 start(){ echo -n " starting $name ;" $path -t test=$? if [ $test -eq 0 ];then touch /tmp/nginx.pid $path echo "$DATE and $path is starting" >> $log else echo "please check you config" exit 20 fi } #停止nginx服务,并把输出的信息重定向到指定的日志文件。 stop(){ echo -n "stopping $name ;" ps -ef |grep nginx | awk '{print $2}' | xargs kill -9 test=0 if [ $test -eq 0 ] ;then rm -rf /tmp/nginx.pid echo "$DATE and $path is stop" >> $log fi } #重加载选项,将服务重新加载并识别服务是否正常运行。 reload(){ echo -n "reloading $name ;" # ps -ef |grep nginx | awk '{print $2}' | xargs kill -9 $path -t test=$? if [ $test -eq 0 ];then touch /tmp/reload.pid echo "$DATE and $path is reloading " >> $log rm -rf /tmp/reload.pid else echo "please check you config" exit 20 fi } #整个脚本使用case方式来进行调用,当执行该脚本时会输出相关信息提醒。 case "$1" in start) start;; stop) stop;; reload) reload;; *) echo "/usr/local/nginx/sbin/nginx start|stop|reload !";; esac ######---退出shell之后,执行以下操作---###### 1.对文件加权限 chmod +x nginxd 2.对文件执行 bash nginxd [start|stop|reload]
相关文章推荐
- linux环境下编写shell脚本启动和关闭jar包服务程序
- shell语句编写nginx的启动脚本
- Nginx启动、关闭、重新加载脚本
- linux 下Nginx启动、关闭、重新加载脚本
- nginx在windows下的安装,以及编写启动关闭nginx等操作的脚本
- 一个nginx启动关闭重启的shell脚本
- CentOS6.8 x86_64bit shell脚本实现模拟nginx服务启动与关闭
- shell脚本启动关闭tomcat,查看日志和备份项目
- linux环境下编写shell脚本实现启动停止tomcat服务的方法
- 使用shell脚本 启动关闭tomcat服务
- oracle学习笔记(二):编写shell脚本启动oracle
- 编写nginx的启动脚本和配置文件
- 编写启动程序和停止程序的shell脚本
- rsync启动关闭shell脚本
- 自己写了个nginx启动脚本,shell
- nginx启动脚本编写
- 使用shell脚本启动关闭memcache服务
- hadoop集群一键自动启动和自动关闭shell脚本 原创 2017年07月23日 17:58:45
- Shell脚本控制tomcat的docker容器的创建,删除,启动,关闭
- nginx 安装、编写启动脚本、配置