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

Mysql sorting and paging (order by & limit) and existing pitfalls

Sorting query (order by) In e-commerce: We want t...

Detailed explanation of various join summaries of SQL

SQL Left Join, Right Join, Inner Join, and Natura...

Nginx local directory mapping implementation code example

Sometimes you need to access some static resource...

CSS hacks \9 and \0 may not work for hacking IE11\IE9\IE8

Every time I design a web page or a form, I am tr...

Solution to the problem of null column in NOT IN filling pit in MySQL

Some time ago, when I was working on a small func...

Mysql modify stored procedure related permissions issue

When using MySQL database, you often encounter su...

3 different ways to clear the option options in the select tag

Method 1 Copy code The code is as follows: documen...

W3C Tutorial (13): W3C WSDL Activities

Web Services are concerned with application-to-ap...

Summary of methods to clear cache in Linux system

1) Introduction to cache mechanism In the Linux s...

JS implements multiple tab switching carousel

Carousel animation can improve the appearance and...

How to Apply for Web Design Jobs

<br />Hello everyone! It’s my honor to chat ...

Solve the matching problem in CSS

Problem Description As we all know, when writing ...

Solution to Mysql binlog log file being too large

Table of contents 1. Related binlog configuration...