首页  >  文章  >  运维  >  nginx自动化脚本怎么写

nginx自动化脚本怎么写

WBOY
WBOY转载
2023-05-31 14:37:061701浏览

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

#!/bin/bash
. /etc/init.d/functions
function 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

nginx自动化脚本怎么写

2.开启nginx

nginx自动化脚本怎么写

3.重启nginx

nginx自动化脚本怎么写

以上是nginx自动化脚本怎么写的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:yisu.com。如有侵权,请联系admin@php.cn删除