supervisord 配置群组管理进程

http://supervisord.org/configuration.html#inet-http-server-section-settings
https://blog.csdn.net/windy135/article/details/90204224
https://blog.csdn.net/diyiday/article/details/79817905
supervisor 表准安装就不详细说了。

pip 方式安装 supervisor

1, pip install supervisor==4.0.4
2, which supervisord 查看suervisor 的安装目录, 并进入supervisord 的安装目录,
3,./echo_supervisord_conf > supervisored.conf   生成配置文件
4, mkdir -p /etc/supervisor/conf.d
    cp supervisored.conf /etc/supervisor/
5, 修改配置文件supervisored.conf
    [include]
     files = conf.d/*.conf
6, 启动supervisord, supervisord会默认查找/etc/supervisor/supervisored.conf 配置文件
   ./supervisord -c /etc/supervisor/supervisored.conf
   

supervisor 群组管理:
1, 配置文件:
command=/home/ansen/anaconda3/bin/gunicorn wsgi -c gunicorn.conf.py
directory=/home/ansen/update_web_server
autostart=true
autorestart=true
redirect_stderr=true
stdout logfile=/var/log/update_web_server.log

[program:update_web_server1]
command=/home/ansen/anaconda3/bin/gunicorn wsgi -c gunicorn.conf1.py
directory=/home/ansen/update_web_server
autostart=true
autorestart=true
redirect_stderr=true
stdout logfile=/var/log/update_web_server1.log


[group:update_svss]
programs=update_web_server,update_web_server1  ; each refers to 'x' in [program:x] definitions
priority=999                  ; the relative start priority (default 999)


command=/home/ansen/anaconda3/bin/gunicorn wsgi -c gunicorn.conf.py
directory=/home/ansen/update_web_server
autostart=true
autorestart=true
redirect_stderr=true
stdout logfile=/var/log/update_web_server.log

[program:update_web_server1]
command=/home/ansen/anaconda3/bin/gunicorn wsgi -c gunicorn.conf1.py
directory=/home/ansen/update_web_server
autostart=true
autorestart=true
redirect_stderr=true
stdout logfile=/var/log/update_web_server1.log

启动supervisorctl 客户端: 显示当前运行进程的状态
(base) root@ansen-VirtualBox:/etc/supervisor/conf.d# supervisorctl
update_svss:update_web_server    RUNNING   pid 17009, uptime 1:10:56
update_svss:update_web_server1   RUNNING   pid 16901, uptime 1:18:33
supervisor>

(base) root@ansen-VirtualBox:/etc/supervisor/conf.d# supervisorctl
update_svss:update_web_server    RUNNING   pid 17009, uptime 1:10:56
update_svss:update_web_server1   RUNNING   pid 16901, uptime 1:18:33
supervisor>
supervisor> stop update_svss all                          //关闭群组内所有进程 注意 stop update_svss 会报错
update_svss:update_web_server: stopped
update_svss:update_web_server1: stopped
supervisor> start update_svss:update_web_server           //启动群组内单个应用进程
update_svss:update_web_server: started
supervisor> start update_svss update_web_server1          // 这种启动方式会报错
update_svss: ERROR (no such process)
update_web_server1: ERROR (no such process)
supervisor> start update_svss:update_web_server1
update_svss:update_web_server1: started
supervisor> stop update_svss                              // 这种关闭方式会报错
update_svss: ERROR (no such process)
supervisor> stop update_svss all
update_svss:update_web_server: stopped
update_svss:update_web_server1: stopped
supervisor> start update_svss all                         //启动群组内所有应用进程
update_svss:update_web_server: started
update_svss:update_web_server1: started

Supervisord 开机启动

1、新建/usr/lib/systemd/system/supervisord.service文件:

# dservice for systemd (CentOS 7.0+)
# by ET-CS (https://github.com/ET-CS)
[Unit]
Description=Supervisor daemon
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=3s
[Install]
WantedBy=multi-user.target

 

2、设置开机启动: systemctl enable supervisord
3、一些常用的systemctl命令:

启动supervisord服务
systemctl start supervisord.service

停止supervisord服务
systemctl stop supervisord.service

重启supervisord服务
systemctl restart supervisord.service

查看supervisord服务当前状态
systemctl status supervisord.service

设置supervisord服务开机自启动
systemctl enable supervisord.service

停止supervisord服务开机自启动
systemctl disable supervisord.service

 

你可能感兴趣的:(supervisord 配置群组管理进程)