美文网首页web开发Golang与区块链
supervisor(进程管理)小白快速上手

supervisor(进程管理)小白快速上手

作者: 老苗 | 来源:发表于2019-07-12 09:58 被阅读0次

    简介

    supervisor是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具。可以很方便的监听、启动、停止、重启一个或多个进程。用supervisor管理的进程,当一个进程意外被杀死,supervisor监听到进程死后,会自动将它重启,很方便的做到进程自动恢复的功能,不再需要自己写shell脚本来控制。

    安装

    sudo apt-get install supervisor
    

    其它安装方式

    使用pip工具

    pip install supervisor
    

    配置文件

    生成

    echo_supervisord_conf > /etc/supervisord.conf
    

    配置文件加载顺序

    默认在当前目录查找supervisord.conf配置文件

    1.$CWD/supervisord.conf
    2.$CWD/etc/supervisord.conf
    3./etc/supervisord.conf
    4./etc/supervisor/supervisord.conf (since Supervisor 3.3.0)
    5.../etc/supervisord.conf (Relative to the executable)
    6.../supervisord.conf (Relative to the executable)

    指定配置文件

    sudo supervisord -c  supervisord.conf
    

    配置程序

    增加自己的一个程序,打开supervisord.conf配置文件

    [program:jshop]
    command=make run              ; the program (relative uses PATH, can take args)
    stdout_logfile=jshop.out      ; stdout log path, NONE for none; default AUTO
    

    注意:make run执行我项目中的Makefile文件
    其它常用程序配置

    ; 环境变量
    ;environment=A="1",B="2"       ; process environment additions
    

    后续学习重点:详细的使用说明,可以打开生成的supervisord.conf配置文件

    运行

    开始服务
    方式一

    sudo supervisord
    

    方式二

    sudo systemctl  start supervisor
    

    开始自定义的程序

    sudo supervisorctl start all
    sudo supervisorctl start [自己配置的名称]
    

    状态

    sudo supervisorctl status all
    

    停止

    sudo supervisorctl stop all
    suod supervisorctl stop [自己配置的名称]
    

    停止supervisord服务

    方式一

    netstat -anp|grep super
    sudo kill [进程id]
    

    方式二

    sudo systemctl stop supervisor
    

    如果停止后,重新启动服务,出错

    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 supervisord.
    解决办法:

    sudo unlink /var/run/supervisor.sock
    sudo unlink /tmp/supervisor.sock
    

    注:以上两种unlink,选择自己supervisor.sock所在的位置

    总结

    以上在supervisor使用的过程中,还有其它使用方式,更详细的去往官网

    相关文章

      网友评论

        本文标题:supervisor(进程管理)小白快速上手

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