Installation and use of Linux operation and maintenance tool Supervisor (process management tool)

Installation and use of Linux operation and maintenance tool Supervisor (process management tool)

1. Introduction

Supervisor is a general process management program developed in Python. It can turn an ordinary command line process into a background daemon, monitor the process status, and automatically restart when it exits abnormally. Currently, Supervisor can run on most Unix systems, but does not support running on Windows systems. Supervisor requires Python 2.4 or later, but does not support any Python 3 versions.

2. Built-in Web Management Program

Supervisor has four components:

1. supervisord
Run the Supervisor background service, which is used to start and manage the subprocesses that you need Supervisor to manage, respond to requests from clients, restart subprocesses that exit unexpectedly, write the subprocess's stdout and stderr to logs, respond to events, etc. It is the core part of Supervisor.

2. supervisorctl
Equivalent to the client of supervisord, it is a command line tool through which users can send instructions to the supervisord service, such as checking the status of subprocesses and starting or shutting down subprocesses. It can connect to different supervisord services, including services on remote machines.

3. Web server This is the Web client of supervisord. Users can complete functions similar to supervisorctl on the Web page.

4. XML-RPC interface This is an interface reserved for third-party integration. Your service can call these XML-RPC interfaces remotely to control the subprocesses managed by supervisord. The above Web server is actually implemented through this XML-RPC interface.

3. Installation

There are three methods below, you can choose any one

1. Installation

echo "supervisor-3.3.4 installation (yes, please enter 1; no, enter other):" 
read SV
if [ "$SV" = "1" ]; then 
	cd $basepath
	unzip $basepath/supervisor-3.3.4.zip 
	cd supervisor-3.3.4
	python setup.py install
	echo "supervisor-3.3.4 installation completed"
else
	echo "You chose not to install supervisor-3.3.4"
fi

2. Source code installation

 wget https://pypi.python.org/packages/7b/17/88adf8cb25f80e2bc0d18e094fcd7ab300632ea00b601cbbbb84c2419eae/supervisor-3.3.4.tar.gz
 tar -zxvf supervisor-3.3.4.tar.gz
 cd supervisor-3.3.4
 python setup.py install #The local python version is python2.7

3. Yum installation

yum install supervisor

4. Configuration File

If there is no /etc/supervisord.conf configuration file after installation, generate it with the command:

echo_supervisord_conf > /etc/supervisord.conf

5. Startup

supervisord -c /etc/supervisord/supervisord.conf 
	echo "supervisor-3.3.4 started successfully"

6. Set up startup

systemctl enable supervisord.service

7. Check if supervisord is running

ps aux | grep supervisord

8. supervisorctl management command

supervisorctl status #status supervisorctl stop nginx #Shutdown nginx
 supervisorctl start nginx #Start nginx
 supervisorctl restart nginx #Restart nginx
 supervisorctl reload #Restart all supervisorctl update #Update configuration

This command can be used separately or in combination.

9. Configuration file description

[unix_http_server]
file=/tmp/supervisor.sock ;UNIX socket file, supervisorctl will use; chmod=0700 ;socket file mode, default is 0700
;chown=nobody:nogroup ;owner of the socket file, format: uid:gid

;[inet_http_server] ;HTTP server, providing web management interface;port=127.0.0.1:9001 ;IP and port of the web management backend. If it is open to the public network, you need to pay attention to security;username=user ;Username for logging in to the management backend;password=123 ;Password for logging in to the management backend [supervisord]
logfile=/tmp/supervisord.log; log file, the default is $CWD/supervisord.log
logfile_maxbytes=50MB; log file size, if exceeded, it will be rotated, default is 50MB, if set to 0, it means no size limitlogfile_backups=10; the default number of log file backups is 10, set to 0 means no backuploglevel=info; log level, default is info, others: debug,warn,trace
pidfile=/tmp/supervisord.pid ;pid file nodaemon=false ;whether to start in the foreground, the default is false, that is, start in daemon mode minfds=1024 ;the minimum value of the file descriptor that can be opened, the default is 1024
minprocs=200; The minimum number of processes that can be opened, the default is 200

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; Connect to supervisord via UNIX socket, the path is consistent with the file in the unix_http_server part; serverurl=http://127.0.0.1:9001 ; Connect to supervisord via HTTP

; [program:xx] is the configuration parameter of the managed process, xx is the name of the process [program:xx]
command=/opt/apache-tomcat-8.0.35/bin/catalina.sh run ; Program startup command autostart=true ; Automatically start when supervisord starts startsecs=10 ; If there is no abnormal exit after 10 seconds of startup, it means that the process started normally. The default is 1 second autorestart=true ; Automatically restart after the program exits. Optional values: [unexpected, true, false], the default is unexpected, which means that the process will restart only after it is accidentally killed startretries=3 ; The number of automatic retries when the startup fails, the default is 3
user=tomcat; Which user is used to start the process, the default is root
priority=999; Process startup priority, default is 999, processes with smaller values ​​are started first redirect_stderr=true; redirect stderr to stdout, default is false
stdout_logfile_maxbytes=20MB; stdout log file size, default 50MB
stdout_logfile_backups = 20 ; Number of stdout log file backups, default is 10
; stdout log file. Please note that it cannot start normally if the specified directory does not exist, so you need to create the directory manually (supervisord will automatically create the log file)
stdout_logfile=/opt/apache-tomcat-8.0.35/logs/catalina.out
stopasgroup=false; default is false, when the process is killed, whether to send a stop signal to the process group, including child processes killasgroup=false; default is false, send a kill signal to the process group, including child processes; contains other configuration files [include]
files =/etc/supervisord.d/*.ini ; You can specify one or more configuration files ending with .ini

10. Example of ini configuration file

[program:MysqlToRedis]
directory = /data/py/SmartServerModel/SmartServerModel/ModelManagerServer/
command = python3 -u mysql2redis_robot_config.py cs
autostart = true
autorestart=true
startsecs = 5
user =root
redirect_stderr = true
stdout_logfile = /data/logs/supervisord/mysqltoredis.log

[program:SmartBinLog]
command = /data/go/src/SmartBinLog/SmartBinLog
autostart = true
autorestart=true
startsecs = 5
user =root
redirect_stderr = true
stdout_logfile = /data/logs/supervisord/smartbinlog.log

[group:nlp]
programs=MysqlToRedis,SmartBinLog ;server,progname2 each refers to 'x' in [program:x] definitions
priority=999 ; the relative start priority (default 999)

11. Open the web page management program

Uncomment all the commented lines in the conf configuration file, and then change the port, username and password

[inet_http_server] ;HTTP server, providing web management interfaceport=127.0.0.1:9001 ;IP and port of the web management backend. If it is open to the public network, please pay attention to securityusername=user ;Username for logging into the management backendpassword=123 ;Password for logging into the management backend

12. Solve the problem of "unix:///tmp/supervisor.sock no such file"

Sometimes we encounter this problem:


The solution is simple:

①. Stop the existing supervisorctl process


②. Modify the configuration file "/etc/supervisord.conf" and change tmp to etc. The files in the /tmp directory will be recycled regularly by the operating system, so you need to modify

③. Start supervisord with the configuration file you just modified, and everything will be back to normal.

You may also be interested in:
  • Linux process management tool supervisor installation and configuration tutorial
  • 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
  • Learn how to use the supervisor watchdog in 3 minutes

<<:  Implementing a simple timer based on Vue method

>>:  Detailed explanation of the implementation steps of MySQL dual-machine hot standby and load balancing

Recommend

Detailed example of MySQL data storage process parameters

There are three types of MySQL stored procedure p...

Use of Linux tr command

1. Introduction tr is used to convert or delete a...

Summary of MySQL lock knowledge points

The concept of lock ①. Lock, in real life, is a t...

Records of using ssh commands on Windows 8

1. Open the virtual machine and git bash window a...

Detailed process of building nfs server using Docker's NFS-Ganesha image

Table of contents 1. Introduction to NFS-Ganesha ...

Hadoop 2.x vs 3.x 22-point comparison, Hadoop 3.x improvements over 2.x

Question Guide 1. How does Hadoop 3.x tolerate fa...

Several solutions for forgetting the MySQL password

Solution 1 Completely uninstall and delete all da...

CSS3 simple cutting carousel picture implementation code

Implementation ideas First, create a parent conta...

How to dynamically add ports to Docker without rebuilding the image

Sometimes you may need to modify or add exposed p...

Detailed examples of using JavaScript event delegation (proxy)

Table of contents Introduction Example: Event del...

Practical notes on installing Jenkins with docker-compose

Create a Directory cd /usr/local/docker/ mkdir je...