Supervisor 超好用的进程管理

Supervisor 是用于监控和管理进程的工具,可以在后台持续运行并确保特定的进程在系统中持续工作

安装

ubuntu安装

# 安装
sudo apt update
sudo apt install supervisor

# 检查状态
sudo systemctl status supervisor

# 启动、开机自启
sudo systemctl start supervisor
sudo systemctl enable supervisor

# 配置服务
cd /etc/supervisor/conf.d

# 记得重新加载
sudo supervisorctl update

其他安装

# 添加 EPEL 软件源
sudo yum install epel-release

# 安装 supervisor
sudo yum install supervisor

# 启动 supervisor
sudo systemctl start supervisord

# 开机自启
sudo systemctl enable supervisord

# 检查状态
systemctl status supervisord

基本命令 

# 查看 supervisor 当前管理的所有进程状态
supervisorctl status

# 启动单个/所有进程
supervisorctl start usercenter
supervisorctl start all 

# 停止进程
supervisorctl stop usercenter        
supervisorctl stop all

# 重启进程
supervisorctl restart usercenter   #或者使用supervisorctl reload: 重启
supervisorctl restart all

# 读取有更新(增加)大的配置文件,不会启动新添加的程序
supervisorctl reread

# 将配置文件里新增的子进程加入进程组,如果设置了autostart=true则会启动新新增的子进程
supervisorctl update

基本配置

[program:theprogramname]
command=/bin/cat              ; 程序运行命令,建议使用绝对路径。
process_name=%(program_name)s ; 程序名称,可用的变量有 `group_name`, `host_node_name`, `process_num`, `program_name`, `here`(配置文件目录)。 一般程序需要运行多个副本的情况会使用。后面会有例子。
numprocs=1                    ; 程序运行的副本个数,默认为1,如果值大于1,则`process_name` 必须包含 `%(process_num)s`
numprocs_start=0              ; `%(process_num)s`起始数字,默认为0
00=/tmp                       ; 程序运行的所在目录,相当于先cd到指定目录,然后运行程序。
umask=022                     ; umask for process (default None)
priority=999                  ; 程序操作的的优先级,例如在start all/stop all,高优先级的程序会先关闭和重启。
autostart=true                ; 在supervisord启动时自动启动,默认为true
startsecs=1                   ; 程序启动前等待时间等待时间。默认为1。
startretries=3                ; 尝试重启最大次数。默认为3。
autorestart=unexpected        ; 是否自动重启,可选参数为 false, unexpected, true。如果为false则不自动重启,如果为unexpected表示如果程序退出信号不在 `exitcodes` 中,则自动重启。默认为unexpected
exitcodes=0,2                 ; 程序退出码。配合`autorestart`使用。默认为 0,2
stopsignal=QUIT               ; 杀死进程时发送的信号,默认为TREM。
stopwaitsecs=10               ; 发送SIGKILL信号前最大等待时间。默认为10。
user=dev                      ; 以指定用户身份启动程序。默认为当前用户。
stopasgroup=false             ; 是否向子进程发送停止信号,这对于Flask的debug模式很有用处,如果设置为true,则不向子进程发送停止信号。默认为false
killasgroup=false             ; 是否向子进程发送kill信号,默认为false
redirect_stderr=false         ; 将错误输出定向到标准输出,默认为false
stdout_logfile=/a/path        ; 标准输出日志路径,可选参数为 `自定义` `AUTO` `NONE`,`自定义`将日志写到自定义路径,可用的变量有`group_name`, `host_node_name`, `process_num`, `program_name`, `here`(配置文件目录);`NONE`不创建日志;`AUTO` 又supervisord自动选择路径,并且当supervisord服务重新启动时原来自动创建的日志以及日志的备份文件会被删除。默认为AUTO
stdout_logfile_maxbytes=1MB   ; 标准输出日志单个文件最大大小,如果超过指定大小会将日志文件备份,可用的单位 KB MB GB。如果设置为0则表示不限制文件大小。默认为50MB
stdout_logfile_backups=10     ; 标准输出日志文件最大备份数。默认为10
stdout_capture_maxbytes=1MB   ; 当进程处于“stdout capture mode”模式下写入到FIFO队列最大字节数,可用单位 KB MB GB。默认为0,详细说明见[capture-mode](http://supervisord.org/logging.html#capture-mode)
stdout_events_enabled=false   ; 
                              ;以下配置项配置错误输出的日志参数。和上面标准输出配置相同。
stderr_logfile=/a/path        ;
stderr_logfile_maxbytes=1MB   ;
stderr_logfile_backups=10     ;
stderr_capture_maxbytes=1MB   ;
stderr_events_enabled=false   ;
environment=A="1",B="2"       ; 环境变量设置,可用的变量有 `group_name`, `host_node_name`, `process_num`, `program_name`, `here`。 默认为空。
serverurl=AUTO                ; override serverurl computation (childutils)

常用配置

  • 13
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值