首页 > 开发 > Nginx > 正文

shell脚本之nginx自动化脚本

2019-10-11 23:36:10
字体:
来源:转载
供稿:网友

这个脚本,可以满足nginx开启,停止和重启的操作

#!/bin/bash. /etc/init.d/functionsfunction usage() {  echo $"usage:$0 {start|stop|restart}"  exit 1}function start() {  /usr/local/nginx/sbin/nginx   sleep 1  if [ `netstat -antlpe | grep nginx | wc -l` -ge 0 ];then action "nginx is started." /bin/true   else action "nginx is started." /bin/false  fi}function stop() {  killall nginx &>/dev/null  sleep 1  if [ `netstat -antlpe | grep nginx | wc -l` -eq 0 ];then action "nginx is stopped." /bin/true  else action "nginx is stopped." /bin/false  fi}function main() {  if [ $# -ne 1 ];then usage $0  fi  case $1 in  start) start ;; stop) stop ;; restart) stop start ;; *) usage $0 ;;  esac}main $*

运行试试

1.停止nginx

shell脚本,nginx,自动化脚本

2.开启nginx

shell脚本,nginx,自动化脚本

3.重启nginx

shell脚本,nginx,自动化脚本

ok~

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对VEVB武林网的支持。


注:相关教程知识阅读请移步到服务器教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表