linux supervisord 基本使用
发表于|更新于
|阅读量:
前言
supervisord 是用 Python 开发的一个进程管理工具
安装
直接使用 pip 直接安装
使用 apt-get 安装
1
| apt-get install supervisor
|
配置文件
supervisor 也有一个配置文件优先路径,$CWD/supervisord.conf
> $CWD/etc/supervisord.conf
> /etc/supervisord.conf
一般会创建一个 /etc/supervisord.conf
,然后创建一个/etc/supervisor/SomeService.conf
, 然后在/etc/supervisord.conf
中包含后者
生成配置文件
1
| echo_supervisord_conf > /etc/supervisord.conf
|
最后一行添加配置,方便管理自定义进程
1 2
| [include] files = /etc/supervisor/*.conf
|
创建自定义脚本文件
1 2 3 4 5 6 7 8 9 10 11 12
| [program:expressbot] directory = /home/ExpressBot/expressbot/main.py command = /usr/bin/python /home/ExpressBot/expressbot/main.py autostart = true startsecs = 5 autorestart = true startretries = 3 user = root redirect_stderr = true stdout_logfile_maxbytes = 20MB stdout_logfile_backups = 20 stdout_logfile = /var/log/expressbot_stdout.log
|
启动 supervisor
1
| supervisord -c /etc/supervisord.conf
|
supervisorctl 管理命令
1 2 3 4 5 6 7
| supervisorctl start projectname supervisorctl stop projectname supervisorctl restart projectname supervisorctl stop all supervisorctl update supervisorctl reload supervisorctl status
|
supervisord 模板
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| [supervisord] nodaemon=true logfile=/dev/null logfile_maxbytes=0 user=root
[include] files = /etc/supervisord.d/*.conf
[program:vncserver] command=/usr/bin/vncserver -localhost no :1 -passwd /root/.vnc/passwd -useold directory=/root
[program:ytdl] directory=/ytdlbot command=python ytdl.py autorestart=true stdout_logfile=/dev/fd/1 stdout_logfile_maxbytes=0 redirect_stderr=true
|