supervisor进程管理工具

supervisor学习

  • 首先安装Supervisor,系统自带pip,因为截至目前Supervisor还不支持Python3,不过并不影响使用。

    pip install supervisor
  • 为了方便,创建目录结构,来管理Supervisor有关的文件:

    /root/etc
    ├── supervisor
    │   ├── conf.d
    │   └── var
    │       ├── log
    └── supervisord.conf
    
  • 首先建立上述的目录结构

    mkdir -p ~/etc/supervisor/conf.d
    mkdir -p ~/etc/supervisor/var/log
  • 然后进入~/etc目录下生成Supervisor的配置文件

    cd ~/etc
    echo_supervisord_conf > supervisord.conf
  • 进入supervisord.conf:

    vim supervisord.conf
  • 首先找到[unix_http_server],更改配置,指定supervisor.sock文件位置。

    [unix_http_server]
    file=/root/etc/supervisor/var/supervisor.sock
  • 更改[supervisord]配置:

    [supervisord]
    logfile=/root/etc/supervisor/var/log/supervisord.log
    pidfile=/root/etc/supervisor/var/supervisord.pid
    user=root
  • 更改[supervisorctl]配置:

    [supervisorctl]
    serverurl=unix:///root/etc/supervisor/var/supervisor.sock
  • 更改[include]配置:

    [include]
    files = /root/etc/supervisor/conf.d/*.ini
  • conf.d新建一个文件newprocess.ini配置uwsgi

    [program:uwsgi]
    command=/opt/west_env/bin/uwsgi --ini /opt/west_coast__company_project/west_coast__company_project/uwsgi.ini
    directory=/opt/west_coast__company_project/west_coast__company_project/
    # 开始等待时间
    startsecs=0
    # 停止等待时间
    stopwaitsecs=0
    autostart=true
    # 进程意外退出时重启
    autorestart=true
    # 进程运行的用户,防止权限问题
    user=root
    stdout_logfile=/root/etc/supervisor/var/log/newprocess-stdout.log
    stderr_logfile=/root/etc/supervisor/var/log/newprocess-stderr.log
    [program:nginx]
    command=/usr/sbin/nginx
    directory=/usr
    startsecs=0
    stopwaitsecs=0
    autostart=true
    autorestart=true
    user=root
    stdout_logfile=/root/etc/supervisor/var/log/nginx-stdout.log
    stderr_logfile=/root/etc/supervisor/var/log/nginx-stderr.log
    [program:redis]
    command=systemctl start redis
    directory=/etc
    startsecs=0
    stopwaitsecs=0
    autostart=true
    autorestart=true
    user=root
    stdout_logfile=/root/etc/supervisor/var/log/redis-stdout.log
    stderr_logfile=/root/etc/supervisor/var/log/redis-stderr.log
    [program:mysql]
    command=systemctl start mariadb
    directory=/etc
    startsecs=0
    stopwaitsecs=0
    autostart=true
    autorestart=true
    user=root
    stdout_logfile=/root/etc/supervisor/var/log/mysql-stdout.log
    stderr_logfile=/root/etc/supervisor/var/log/mysql-stderr.log
  • 启动管理进程命令

    /usr/bin/supervisord -c ~/etc/supervisord.conf
  • 查看是否启动成功

    ps -ef | grep supervisor
  • 进入 supervisorctl 进程管理控制台 :

/usr/bin/supervisorctl -c ~/etc/supervisord.conf
  • 启动

    reload
    start all
    stop all
    restart uwsgi(uwsgi指定program配置名字)
上一篇:使用supervisor后台运行celery


下一篇:centos上安装python环境