Supervisor [note]

Supervisor – H view supervisor command help

Supervisorctl – H view supervisorctl command help

Supervisorctl help view the action command of supervisorctl

Supervisorctl help any action to view the use of this action

1. Introduction

Supervisor is a process control system. Generally speaking, it can monitor your process. If the process exits abnormally, it can automatically help you restart the process. So we can use it to monitor the queue consumption process and so on

2. Installation

2.1 install using package manager (not the latest version installed)

# Ubuntu 
sudo apt install supervisor

# Centos
sudo yum install supervisor

2.2 installation with PIP

pip install supervisor

3. Create a profile

After the supervisor is installed, runecho_supervisord_confCommand, the default configuration will be output at the terminal. After seeing the configuration content, runecho_supervisord_conf > /etc/supervisord.confExport default configuration to/etc/supervisord.confThe configuration file is created

4. Start the supervisor

Run directly at the terminalsupervisordThe supervisor will be started. This command is used by default/etc/supervisord.confThis configuration file. If you want to start the supervisor with a custom configuration file, runSupervisor - C configuration file.

5. Use Supervisor

Supervisor hassupervisord, supervisorctl, Web Server, XML-RPC InterfaceFour parts:

  1. supervisordUsed to start the server process
  2. supervisorctlIt is equivalent to starting a client to manage the processes under it
  3. Web ServerProvide web services to facilitate you to view the process status
  4. XML-RPC Interface(not used)

6. Common commands

There are two ways to use it. You can input it directly at the terminalsupervisorctlStart the client and enterstatus updateSuch commands to manage the process. Or enter it directlysupervisorctl status supervisorctl update .

  • status:  View program status
  • stop:  close program
  • start:  Start program
  • restart:  Restart program
  • reread:  Reading the updated configuration file will not restart the process
  • update:  Restart the program whose configuration file has been modified
  • tail:  View process log

7. Process profile

;  Process prefix after colon
;  Process name
;  Command to run the process
command=php /home/forge/ queue:work sqs --sleep=3 --tries=3
;  If true, the program will start automatically when supervisor starts
;  Automatically restart when program exit is detected
;  User running the process
;  Number of processes
;  Redirect error flow to standard output, equivalent to 2 > & 1
;  Standard log output file

The default configuration ends with the following paragraph:

files = supervisord.d/*.ini

It means that the supervisor will read. ini under supervisor. DFile, so name and save your configuration file as required

8. Command details

8.1 cleaning log

clear <name>            Clear a process' log files.
clear <name> <name>     Clear multiple process' log files
clear all               Clear all process' log files

8.2 restart process

restart <name>          Restart a process
restart <gname>:*       Restart all processes in a group
restart <name> <name>   Restart multiple processes or groups
restart all             Restart all processes
Note: restart does not reread config files. For that, see reread and update

8.3 start process

start <name>            Start a process
start <gname>:*         Start all processes in a group
start <name> <name>     Start multiple processes or groups
start all               Start all processes

8.4 stopping the process

stop <name>             Stop a process
stop <gname>:*          Stop all processes in a group
stop <name> <name>      Stop multiple processes or groups
stop all                Stop all processes

8.5 update: reload the configuration and add or remove processes as needed

update                  Reload config and add/remove as necessary
update all              Reload config and add/remove as necessary
update <gname> [...]    Update specific groups

8.6 show all management processes

avail                   Display all configured processes

8.7 reload: restart Supervisor (operations to modify supervisor.conf)

reload          Restart the remote supervisord

8.8 reread: read the updated configuration file without restarting the process

reread                  Reload the daemon's configuration files

8.9 end the supervisor process

shutdown        Shut the remote supervisord down

8.10 viewing process status

status <name>           Get status for a single process
status <gname>:*        Get status for all processes in a group
status <name> <name>    Get status for multiple named processes
status                  Get all process status info

9. Excellent links

This work adoptsCC agreement, reprint must indicate the author and the link to this article