Supervisor是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统。它可以很方便的监听、启动、停止、重启一个或多个进程。用Supervisor管理的进程,当一个进程意外被杀死,supervisort监听到进程死后,会自动将它重新拉起,很方便的做到进程自动恢复的功能,不再需要自己写shell脚本来控制。
Github https://github.com/Supervisor/supervisor
官方文档 http://supervisord.org/
安装
yum -y install supervisord
配置
服务自启
systemctl enable supervisord.service
启动服务
systemctl start supervisord.service
配置文件
/etc/supervisord.conf
进程配置文件目录
/etc/supervisord.d/
配置进程
新建并添加以下内容(文件扩展名为ini,在配置文件中配置)
vim /etc/supervisord.d/v2ray.ini
[program:v2ray]
command=/usr/local/v2ray/v2ray -config=/usr/local/v2ray/config.json
stdout_logfile=/usr/local/v2ray/supervisor_v2ray.log
autostart=true
autorestart=true
startsecs=5
priority=1
stopasgroup=true
killasgroup=true
管理进程
命令帮助
supervisorctl help
查看进程状态
supervisorctl status
启动进程
supervisorctl start v2ray
重启进程
supervisorctl restart v2ray
停止进程
supervisorctl stop v2ray
配置文件参数说明
1 | [unix_http_server] |
疑难问题
(1) Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting
解决方案:
find / -name supervisor.sock
unlink /run/supervisor/supervisor.sock