用shell编写nginx脚本的启动,关闭,重加载
发布时间:2020-12-15 16:32:00 所属栏目:安全 来源:网络整理
导读:#!/bin/bash----默认执行shell方式#chkconfig:23451080----加入到开机执行的方式path="/usr/local/nginx/sbin/nginx"----源代码安装nginx之后的启动路径name="nginxd"test=0log=/tmp/nginxd.log----nginx的日志DATE=`date"+%F%H:%M:%S"`----获得系统时间命令
#!/bin/bash----默认执行shell方式 #chkconfig:23451080----加入到开机执行的方式 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}notinstalled!" exit10 fi #启动选项,对执行nginx进行启动,启动成功或者失败都会输出提醒。 start(){ echo-n"starting$name;" $path-t test=$? if[$test-eq0];then touch/tmp/nginx.pid $path echo"$DATEand$pathisstarting">>$log else echo"pleasecheckyouconfig" exit20 fi } #停止nginx服务,并把输出的信息重定向到指定的日志文件。 stop(){ echo-n"stopping$name;" ps-ef|grepnginx|awk'{print$2}'|xargskill-9 test=0 if[$test-eq0];then rm-rf/tmp/nginx.pid echo"$DATEand$pathisstop">>$log fi } #重加载选项,将服务重新加载并识别服务是否正常运行。 reload(){ echo-n"reloading$name;" # ps-ef|grepnginx|awk'{print$2}'|xargskill-9 $path-t test=$? if[$test-eq0];then touch/tmp/reload.pid echo"$DATEand$pathisreloading">>$log rm-rf/tmp/reload.pid else echo"pleasecheckyouconfig" exit20 fi } #整个脚本使用case方式来进行调用,当执行该脚本时会输出相关信息提醒。 case"$1"in start)start;; stop)stop;; reload)reload;; *)echo"/usr/local/nginx/sbin/nginxstart|stop|reload!";; esac ######---退出shell之后,执行以下操作---###### 1.对文件加权限 chmod+xnginxd 2.对文件执行 bashnginxd[start|stop|reload] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读