Learn how to use the supervisor watchdog in 3 minutes

Learn how to use the supervisor watchdog in 3 minutes

Software and hardware environment

  • centos7.6.1810 64bit
cat /etc/redhat-release # View the system version
  • supervisor 3.4.0
  • Python 2.7.5

Supervisor Introduction

Supervisor is a process management tool written in Python. It can easily monitor, start, stop, and restart one or more processes. When a process is killed unexpectedly, the supervisor can monitor the process death and easily restore the process automatically, without the need for programmers or system administrators to write code to control it.

Supervisord installation

yum install -y epel-release
yum install -y supervisor

Start & Enable Auto-Start

systemctl start supervisord
systemctl enable supervisord

Other commands:

systemctl stop supervisord #Stop and startsystemctl start supervisord #Startsystemctl status supervisord #Start statussystemctl reload supervisord #Heavy loadsystemctl restart supervisord #Restart

Supervisor's web client

Supervisor provides web-based control. Administrators can start and restart processes by clicking buttons on the page, which is very convenient.

Enter the configuration file and enable support for the web client

vim /etc/supervisord.conf

If it is provided for external access, the port needs to be changed to the local IP address

#Uncomment lines 10-13. The numbers in front are line numbers [inet_http_server] ; inet (TCP) server disabled by default
port=192.168.26.121:9001 ; (ip_address:port specifier, *:port for all iface)
username=user ; (default is no username (open server))
password=123 ; (default is no password (open server))

After the configuration is complete, restart the service

systemctl restart supervisord

supervisord application configuration

Enter the supervisord configuration file

cat /etc/supervisord.conf

The last line of the configuration file shows

[include]
files = supervisord.d/*.ini

That is to say, all our application configuration files are saved in this directory and saved in .ini format. You can modify the address by yourself, but do not modify the suffix

So let's create a monitored application

Create a test python configuration

Create an application configuration called python

vim /etc/supervisord.d/python.ini

Configuration file content, where command is the command that needs to be executed when our application starts

[program:python] #The python here is the monitoring name we display on the web front end and the terminal command=python /tmp/supervisordtest/test.py #The file address we want to monitor autostart=true
autorestart=true
startsecs=1
startretries=3
redirect_stderr=true
stdout_logfile=/tmp/supervisordtest/access_python.log #Log address, you can configure the directory yourself stderr_logfile=/tmp/supervisordtest/error_python.log #Log address, you can configure the directory yourself

Create test.py

mkdir /tmp/supervisordtest
vim /tmp/supervisordtest/test.py

Program content: Start an infinite loop and keep printing content

while True:
 print(100)

Restart supervisord to make the configuration file take effect

systemctl restart supervisord

Check whether the application starts normally

1. Command view

systemctl status supervisord

2. Visual web viewing

The web terminal can restart, stop, clean up logs, view logs and other operations

Several commands related to supervisor

After the installation is complete, three system commands supervisorctl , supervisord and echo_supervisord_conf will be generated.

1. supervisord , when running supervisor , a process supervisord will be started, which is responsible for starting the managed process and starting the managed process as its own child process, and can automatically restart the managed process when it crashes

2. supervisorctl is a command line management tool that can be used to execute s tart , stop , restart and other commands to manage these subprocesses, such as

sudo supervisorctl start demoweb

demoweb is the name of the process. For detailed commands and instructions, see the table below.

Commands Description
supervisorctl start program_nameStart a process
supervisorctl stop program_nameStop a process
supervisorctl restart program_name Restart a process
supervisorctl status program_name Check the status of a process
supervisorctl stop all Stop all processes | \
supervisorctl reload Load the latest configuration file and restart all processes
supervisorctl update Restart the processes whose configurations have been changed according to the latest configurations. The processes that have not been updated will not be affected.

3. echo_supervisord_conf

Used to generate the default configuration file (the default configuration file is very complete and has comments, suitable for reference when needed, the usage is as follows

echo_supervisord_conf > test.conf

This is the end of the article about how to learn to use supervisor watchdog in 3 minutes. For more information about how to use supervisor in 3 minutes, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Linux process management tool supervisor installation and configuration tutorial
  • Installation and use of Linux operation and maintenance tool Supervisor (process management tool)
  • Installation, configuration and use of process daemon supervisor in Linux
  • Detailed explanation of Supervisor installation and configuration (Linux/Unix process management tool)
  • PHP programmers play Linux series using supervisor to implement daemon process

<<:  Discussion on the way to open website hyperlinks

>>:  A preliminary understanding of CSS custom properties

Recommend

Summary of the most commonly used knowledge points about ES6 new features

Table of contents 1. Keywords 2. Deconstruction 3...

Press Enter to automatically submit the form. Unexpected discovery

Copy code The code is as follows: <!DOCTYPE ht...

How to simply encapsulate axios in vue

Inject axios into Vue import axios from 'axio...

Invalid solution when defining multiple class attributes in HTML

In the process of writing HTML, we often define mu...

Summary of Docker Data Storage

Before reading this article, I hope you have a ba...

6 inheritance methods of JS advanced ES6

Table of contents 1. Prototype chain inheritance ...

Detailed explanation of how to create an array in JavaScript

Table of contents Creating Arrays in JavaScript U...

Button is stretched on both sides in IE

When you write buttons (input, button), you will f...

Detailed explanation of viewing and setting SQL Mode in MySQL

Viewing and Setting SQL Mode in MySQL MySQL can r...

CSS transparent border background-clip magic

This article mainly introduces the wonderful use ...

Bootstrap 3.0 study notes grid system case

Preface In the previous article, we mainly learne...

Detailed explanation of the difference between CSS link and @import

How to add css in html? There are three ways to s...