商城首页欢迎来到中国正版软件门户

您的位置:首页 > 编程开发 >nginx自动化脚本怎么写

nginx自动化脚本怎么写

  发布于2025-05-16 阅读(0)

扫一扫,手机访问

这个脚本,可以满足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自动化脚本怎么写

本文转载于:https://www.yisu.com/zixun/589434.html 如有侵犯,请联系admin@zhengruan.com删除

热门关注