CentOS下Supervisor的安装与使用入门

【转载】http://www.51bbo.com/archives/2120

Supervisor是一个进程管理工具,官方的说法

用途就是有一个进程需要每时每刻不断的跑,但是这个进程又有可能由于各种原因有可能中断。当进程中断的时候我希望能自动重新启动它,此时,我就需要使用到了Supervisor

这个工具主要就两个命令:

supervisord : supervisor的服务器端部分,启动supervisor就是运行这个命令

supervisorctl:启动supervisor的命令行窗口。

安装(Centos):

  1. # yum install python-setuptools
  2. # easy_install supervisor
  3. 如果easy_install不好使就从官方下载:
  4. 然后通过python安装:
  5. # tar zxf supervisor-3.1.3.tar.gz
  6. # cd supervisor
  7. # python setup.py install

成功安装后可以登陆python控制台输入import supervisor 查看是否能成功加载。

生成配置文件(supervisord.conf):

echo_supervisord_conf > /etc/supervisord.conf

修改配置文件:

在supervisord.conf最后增加(分号后边的表示注释,可以不写):

  1. [program:bandwidth]
  2. command=python26 /usr/local/bin/bandwidth.sh  ;需要执行的命令wd)
  3. user =root  ;(default  is  current  user , required  if  root)
  4. autostart=true  ;start at supervisord start (default: true)
  5. autorestart=true  ;whether/when to restart (default: unexpected)
  6. startsecs=3  ;number of secs prog must stay running ( def . 1)
  7. stderr_logfile=/tmp/bandwidth_err.log  ;redirect proc stderr to stdout (default false) 错误输出重定向
  8. stdout_logfile=/tmp/bandwidth.log  ;stdout log path, NONE  for none; default AUTO, log输出
  9. (更多配置说明请参考:http://supervisord.org/configuration.html)
运行命令:

supervisord -c /etc/supervisord.conf  //启动supervisor

supervisorctl //打开命令行

  1. [root @iZ2365j7l5bZ  bin]# supervisorctl status   
  2. bandwidth                        RUNNING   pid  2423 , uptime  0 : 06 : 35
  3. [root @iZ2365j7l5bZ  bin]# supervisorctl help   
  4. default  commands (type help <topic>):   
  5. =====================================   
  6. add    clear  fg        open  quit    remove  restart   start   stop  update    
  7. avail  exit   maintail  pid   reload  reread  shutdown  status  tail  version 

ctl中: help //查看命令

ctl中: status //查看状态

另外有一个坑需要注意:如果修改了 /etc/supervisord.conf ,需要执行 supervisorctl reload 来重新加载配置文件,否则不会生效。。。

原文地址:https://www.cnblogs.com/WangShengguang/p/5331973.html