Supervisor 简单使用

1. 简介

Supervisor is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems.

Supervisor是一个客户端/服务器系统,能够帮助用户监控和管理运行在类 UNIX 系统上的进程。

2. 安装

两种安装方式

  1. 通过 pip 安装(推荐)

    pip install supervisor
    
  2. 通过发行包直接安装

    # ubuntu Debian
    apt install supervisor
    # Centos Redhat 
    yum install supervisor
    

3. 使用

  1. 生成默认配置

    echo_supervisord_conf > /etc/supervisord.conf
    
  2. 修改默认配置

    vim /etc/supervisord.conf
    

    跳到最后,修改以下几行:(千万不要忽视了[include]前面的分号!)

    ;[include]
    ;files = /etc/supervisor/*.ini
    

    去掉开头的 “ ; ”,使这两行生效。(一定注意,这两行都要取消注释!

    这两行的作用就是,将/etc/supervisor/目录下所有的.ini文件都包含到这个配置文件里来。

  3. 编写自己的配置

    进入/etc/supervisor/目录,编写自己的配置文件

    vim myCelery.ini
    

    配置文件内容实例(如需了解配置文件的含义,请查看官方文档)

    [program:mp_celery]  # 这个是进程的名字,随意起
    command=/root/test/venv/bin/celery -B -A Platform worker -l info  # 要运行的命令
    directory=/root/mpform/Platform  # 运行命令的目录
    
    numprocs=1
    # 设置log的路径
    stdout_logfile=/var/log/supervisor/mp_celery.log
    stderr_logfile=/var/log/supervisor/mp_celery_error.log
    autostart=true
    autorestart=true
    startsecs=10
    stopwaitsecs = 10
    priority=15
    
  4. 启动 Supervisor

    # supervisord -c /path/to/config
    supervisord -c /etc/supervisord.conf
    
  5. 查看执行状态

    supervisorctl
    

    如果输出结果如上图,就说明成功了。

    如果不是这样的,可以去/var/log/supervisor目录下查看日志,是不是有什么错误。

    常用命令

    status       # 查看状态
    reread       # 读取配置信息
    update       # 加载最新的进程
    stop         # 停止进程
    start        # 启动进程
    reload       # 重新加载配置
    

参考链接

  1. Supervisor 官方文档
  2. 使用supervisor后台运行celery
原文地址:https://www.cnblogs.com/ljz-2014/p/11608801.html