进程管理supervisor

来源:互联网 发布:知乎女神王诺诺是谁 编辑:程序博客网 时间:2024/06/05 21:14

安装
yum -y install supervisor
建议用yum安装,自动生成服务文件/usr/lib/systemd/system/supervisord.service
pip install supervisor

卸载

pip uninstall supervisoryum uninstall supervisor

配置文件
自动生成配置文件/etc/supervisord.conf

[program:myapp]command=/home/myproject/venv/bin/gunicorn -w4 -b0.0.0.0:8000 myapp:app    ; supervisor启动命令directory=/home/myproject                                                 ; 项目的文件夹路径startsecs=0                                                               ; 启动时间stopwaitsecs=0                                                            ; 终止等待时间autostart=false                                                           ; 是否自动启动autorestart=false                                                         ; 是否自动重启stdout_logfile=/home/myproject/log/gunicorn.log                           ; log 日志stderr_logfile=/home/myproject/log/gunicorn.err                           ; 错误日志

子进程路径/etc/supervisord.d/
服务配置文件/usr/lib/systemd/system/supervisord.service

基本命令

supervisord -c supervisord.conf                             通过配置文件启动supervisorsupervisorctl -c supervisord.conf status                    察看supervisor的状态supervisorctl -c supervisord.conf reload                    重新载入 配置文件supervisorctl -c supervisord.conf start [all]|[appname]     启动指定/所有 supervisor管理的程序进程supervisorctl -c supervisord.conf stop [all]|[appname]       关闭指定/所有 supervisor管理的程序进程
查看所有子进程#supervisorctl statusfailprocess                      RUNNING   pid 712, uptime 96 days, 6:05:15getphonehome                     RUNNING   pid 703, uptime 96 days, 6:05:15parserun                         RUNNING   pid 1408, uptime 35 days, 21:21:28recelery:recelery_00             RUNNING   pid 12008, uptime 16:55:40recelery:recelery_01             RUNNING   pid 12001, uptime 16:55:41recelery:recelery_02             RUNNING   pid 11988, uptime 16:55:42recelery:recelery_03             RUNNING   pid 11987, uptime 16:55:42releasegunicorn                  RUNNING   pid 11922, uptime 16:55:52timecron                         RUNNING   pid 1318, uptime 96 days, 6:05:09useMoney                         RUNNING   pid 23699, uptime 22 days, 2:20:11单个子进程#supervisorctl start/stop/restart/status useMoney#supervisorctl start/stop/restart/status all

web界面操作

需要在supervisor的配置文件里添加[inet_http_server]选项组:之后可以通过http://127.0.0.1:9001来访问控制子线程的管理。[inet_http_server]         ; inet (TCP) server disabled by defaultport=127.0.0.1:9001        ; (ip_address:port specifier, *:port for all iface)username=user              ; (default is no username (open server))password=123               ; (default is no password (open server))

开机自启
开机自启:systemctl enable supervisord.service
其他命令: systemctl start/restart/stop/status supervisord.service