Shell script nginx automation script

Shell script nginx automation script

This script can satisfy the operations of starting, stopping and restarting 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 $*

Run the test

1. Stop nginx

2. Enable nginx

3. Restart nginx

ok~

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Detailed process of installing nginx with shell script source code
  • How to install nginx under Linux
  • Detailed explanation of putting common nginx commands into shell scripts
  • Example of implementing nginx self-starting script under centos/rhel
  • Shell script to install Nginx service and customize Nginx version in one click

<<:  Detailed explanation of 6 ways of js inheritance

>>:  Example of using JSX to create a Markup component style development (front-end componentization)

Recommend

Introduction to the use of common Dockerfile commands

Table of contents 01 CMD 02 ENTRYPOINT 03 WORKDIR...

Building a Redis cluster on Docker

Table of contents 1. Pull the image 2. Create a R...

The most complete package.json analysis

Table of contents 1. Overview 2. Name field 3. Ve...

Convert psd cut image to div+css format

PSD to div css web page cutting example Step 1: F...

Share the responsive frameworks commonly used by web design masters (summary)

This article introduces and shares the responsive...

How to implement nginx smooth restart

1. Background During the server development proce...

How to upgrade https under Nginx

Purchase Certificate You can purchase it from Ali...

Use of Linux passwd command

1. Command Introduction The passwd command is use...

Steps to create a Vite project

Table of contents Preface What does yarn create d...

HTML Tutorial: Collection of commonly used HTML tags (4)

These introduced HTML tags do not necessarily ful...

jQuery implements time selector

This article example shares the specific code of ...

WeChat applet implements calculator function

This article shares the specific code for the WeC...

Zookeeper stand-alone environment and cluster environment construction

1. Single machine environment construction# 1.1 D...

Detailed explanation of selinux basic configuration tutorial in Linux

selinux ( Security-Enhanced Linux) is a Linux ker...