Skip to content

Supervisor 的配置与使用

官网地址:http://supervisord.org/

安装

bash
pip install supervisor

配置

运行 echo_supervisord_conf 命令生成配置

bash
mkdir -p /etc/supervisor/conf.d
echo_supervisord_conf > /etc/supervisor/supervisord.conf

修改配置文件,在文件最后添加

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

启动

bash
supervisord -c /etc/supervisor/supervisord.conf

supervisorctl 用法

http://supervisord.org/running.html#running-supervisorctl

bash
supervisorctl status                # 查看进程运行状态
supervisorctl update                # 更新配置,会重启配置改动的进程
supervisorctl reload                # 重载,会重新加载配置,同时重启所有进程
supervisorctl restart all/<name>    # 重启所有或单个进程,重启不会重载配置
supervisorctl stop all/<name>       # 停止进程
supervisorctl clear all/<name>      # 清理日志
supervisorctl tail -f <name>        # 查看日志

配置示例

文件路径:/etc/supervisor/conf.d/celery.ini

ini
; ==================================
;  celery worker supervisor example
; ==================================

[program:celery]
; Set full path to celery program if using virtualenv
command=pipenv run celery -A popop worker -l info --concurrency=16

directory=/data/devops/current
user=root
numprocs=1
stdout_logfile=/var/log/supervisor/celery.log
stderr_logfile=/var/log/supervisor/celery.log
autostart=true
autorestart=true
startsecs=10

; Need to wait for currently executing tasks to finish at shutdown.
; Increase this if you have very long running tasks.
stopwaitsecs = 600

; When resorting to send SIGKILL to the program to terminate it
; send SIGKILL to its whole process group instead,
; taking care of its children as well.
killasgroup=true

; Set Celery priority higher than default (999)
; so, if rabbitmq is supervised, it will start first.
priority=1000
environment=LC_ALL="en_US.UTF-8",LC_CTYPE="en_US.UTF-8"