supervisord安装使用简记

What is supervisor

Supervisor is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems.

引用自supervisor官网,中文意思就是是一个C/S架构的系统,用来监控管理类UNIX系统上进程。

Features

简单,高效,可扩展,兼容性好(Orz,其实不能在windows上用)

想看更多请去官网

Installing

  1. 因为是用Python实现的,所以最简单的方式是pip install supervisor
  2. ubuntu系统上也可以直接使用sudo apt-get install supervisor

Configure

  • 使用 echo_supervisord_conf 就可以看到默认的配置文件,如下:
➜  Log echo_supervisord_conf  
; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
;
; Notes:
;  - Shell expansion ("~" or "$HOME") is not supported.  Environment
;    variables can be expanded using this syntax: "%(ENV_HOME)s".
;  - Comments must have a leading space: "a=b ;comment" not "a=b;comment".
  • 配置文件

使用 echo_supervisord_conf > /etc/supervisord.conf命令将配置文件保存在xx下面,然后修改配置文件。推荐的方式是将最后一行修改到某个固定文件夹,如下:

[include]
files = /etc/supervisord.d/*.ini

这样每次运行都会加载此目录下的配置文件,每个文件单独管理一个进程。而*.ini的内容一般如下:

配置1
[program:simpleserver]
command=python -m SimpleHTTPServer  # 执行的命令 ,若是虚拟环境则需要注意命令的路径,见配置2
directory=/home/wang/Downloads  # 执行命令的路径
user=wang  #  执行命令的用户
autorestart=true  # 出错后自动重启
redirect_stderr=true  # 错误日志重定向
stdout_logfile=/home/wang/Log/SimpleHTTPServer.log  # 日志的路径
loglevel=info  # 日志的级别
配置2
[program:hongbaoyun]
command=/home/wang/.virtualenvs/xxx-virtual-env/bin/python manage.py runserver 0.0.0.0:9999  # 此处python位置是virtualenv中python的位置
directory=/home/wang/Workspace/khb/hongbaoyun
user=wang

Run

  • 启动
    supervisord -c supervisord.conf # 指定配置文件启动supervisord

  • 启动spuervisordctl
    supervisordctl

  • supervisordctl常用命令

supervisorctl stop program_name  # 停止某一个进程,program_name 为 [program:x] 里的 x

supervisorctl start program_name  # 启动某个进程

supervisorctl restart program_name  # 重启某个进程

supervisorctl stop groupworker:  # 结束所有属于名为 groupworker 这个分组的进程 (start,restart 同理)

supervisorctl stop groupworker:name1  # 结束 groupworker:name1 这个进程 (start,restart 同理)

supervisorctl stop all  # 停止全部进程,注:start、restartUnlinking stale socket /tmp/supervisor.sock
、stop 都不会载入最新的配置文件

supervisorctl reload  # 载入最新的配置文件,停止原有进程并按新的配置启动、管理所有进程

supervisorctl update  # 根据最新的配置文件,启动新配置或有改动的进程,配置没有改动的进程不会受影响而重启
  • 图行管理界面

在配置文件中去掉 [inet http server]的注释就可在浏览器中通过127.0.0.1:8000中看到图形管理界面

FAQ

Refer

posted @ 2016-08-22 17:37  wswang  阅读(12806)  评论(2编辑  收藏  举报