Configuration and use of Supervisor

Keywords: supervisor Celery Python Tomcat

brief introduction

python deployment has always been a problem, but now it's 2018, and there are many mature solutions. The most commonly used is nginx + upervisor + virtualenv + gunicorn / uwsgi.
The advantage is that it is very convenient to control program start / stop / restart, especially when you have many services; but abusing restart is another problem, which is not necessarily to hope you abuse it.

It is divided into two parts:
Supervisor: Server
Supervisor CTL: client

socket or http can be configured for communication between client and server. If it is a stand-alone device, this configuration is not needed, as follows:

serverurl=unix:///tmp/supervisor.sock ;

For multiple computers, it is better to configure http mode communication as follows:

serverurl= ;


pip install supervisor

Note: at present, the supervisor does not support python3, and can only use python2, but does not affect its services that control python3 or even Java PHP.

To configure

sudo mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.conf

Profile interpretation

[program:Project name]
command=python3; Program start command
autostart=true       ; stay supervisord It starts automatically when it starts
startsecs=10         ; If there is no abnormal exit after 10 seconds of starting, it means that the process is started normally. The default is 1 second
autorestart=true     ; Automatic restart after program exit,Optional values:[unexpected,true,false],Default is unexpected,Indicates that the process is not restarted until it is accidentally killed
startretries=3       ; Number of automatic retries for startup failure, default is 3
user=tomcat          ; Which user is used to start the process? The default is root
priority=999         ; Process start priority, 999 by default, priority start with small value
redirect_stderr=true ; hold stderr Redirect to stdout,default false
stdout_logfile_maxbytes=20MB  ; stdout Log file size, default 50 MB
stdout_logfile_backups = 20   ; stdout Number of log file backups, default is 10
; stdout For log files, it should be noted that when the specified directory does not exist, it cannot be started normally, so you need to create the directory manually( supervisord Automatically create log file)
stopasgroup=false     ;Default is false,Whether to send to this process group when the process is killed stop Signals, including subprocesses
killasgroup=false     ;Default is false,Send to process group kill Signals, including subprocesses

Configuration instance

Suppose I have a python server, such as flask and cellery.

command=celery -A application.celery worker -c 6 --beat -l info

[program: X_server]
command=gunicorn -b -w 4 run:app info  --error-logfile logs/error.log --log-file logs/app.log --access-logfile logs/access.log

priority is configured here to ensure that you can start cellery first, and then start x? Server.


python2 /usr/bin/supervisord -c /etc/supervisor/supervisord.conf


Start / stop / restart, "all" represents all services.

supervisorctl start celery
supervisorctl stop celery
supervisorctl restart celery
supervisorctl start X_server
supervisorctl stop X_server
supervisorctl restart X_server
supervisorctl restart all

WEB management page

Generally, it is not used, but if there are too many services, it is another matter. Modify the configuration as follows:

port=          ; ip & port The default is 9001. If it's occupied, change it
password=123               ; There is no user name or password by default. Add it if necessary

Then access to port 9001.

Posted by sri2002 on Mon, 16 Dec 2019 09:24:01 -0800