美文网首页
快速使用Supervisor管理进程(程序自动重启)

快速使用Supervisor管理进程(程序自动重启)

作者: SeanCheney | 来源:发表于2020-07-14 11:07 被阅读0次

    Supervisor是一个用Python写成的进程管理工具,见https://github.com/Supervisor/supervisor

    1. Centos安装supervisor:
    yum install supervisor
    
    1. 生成配置文件(conf文件的位置可修改):
    echo_supervisord_conf > /data/wechat/supervisor/supervisord.conf
    
    1. supervisord.conf中添加如下信息:
    ### 加入以下配置信息
    [include]
    files = /data/wechat/supervisor/supervisord.d/*.conf
    
    ### 在supervisord.conf中设置通过web可以查看管理的进程,加入以下代码(默认即有,取消注释即可)    
    [inet_http_server] 
    port=9001
    username=user      
    password=123
    
    1. 写配置文件,放到/data/wechat/supervisor/supervisord.d/中:

    如果代码要起多个进程:

    [program:appMetaSpider_downloader]
    command=/data/wechat/miniconda3/envs/venv_meta/bin/python xxxxxx.py    ; 被监控的进程路径
    directory=/data/wechat/xxxxxx                ; 执行前要不要先cd到目录去,一般不用
    priority=1                    ;数字越高,优先级越高
    process_name=%(program_name)s_%(process_num)02d ;多进程名称肯定不同,匹配多个
    numprocs=4                    ; 启动几个进程
    autostart=true                ; 随着supervisord的启动而启动
    autorestart=true              ; 自动重启。。当然要选上了
    startretries=10               ; 启动失败时的最多重试次数
    exitcodes=0                   ; 正常退出代码(是说退出代码是这个时就不再重启了吗?待确定)
    stopsignal=KILL               ; 用来杀死进程的信号
    stopwaitsecs=10               ; 发送SIGKILL前的等待时间
    redirect_stderr=true          ; 重定向stderr到stdout
    

    如果是单个进程:

    # supervisor_appMetaSpider_scheduler.conf
    [program:appMetaSpider_parser]
    command=/data/wechat/miniconda3/envs/venv_meta/bin/python xxxxxxx.py    ; 被监控的进程路径
    directory=/data/wechat/xxxxxxx                ; 执行前要不要先cd到目录去,一般不用
    priority=1                    ;数字越高,优先级越高
    numprocs=1                    ; 启动几个进程
    autostart=true                ; 随着supervisord的启动而启动
    autorestart=true              ; 自动重启。。当然要选上了
    startretries=10               ; 启动失败时的最多重试次数
    exitcodes=0                   ; 正常退出代码(是说退出代码是这个时就不再重启了吗?待确定)
    stopsignal=KILL               ; 用来杀死进程的信号
    stopwaitsecs=10               ; 发送SIGKILL前的等待时间
    redirect_stderr=true          ; 重定向stderr到stdout
    
    1. 启动supervisor:
    supervisord -c /data/wechat/supervisor/supervisord.conf
    
    1. 可以访问地址 http://ip_address:9001 查看进程列表

    相关文章

      网友评论

          本文标题:快速使用Supervisor管理进程(程序自动重启)

          本文链接:https://www.haomeiwen.com/subject/eesxhktx.html