supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启。

1 下载程序并安装

yum install python-setuptools
easy_install supervisor

使用root身份创建一个全局配置文件

#echo_supervisord_conf > /etc/supervisord.conf

2 编辑配置文件

vim /etc/supervisord.conf

加入以下内容,directory 指向工程所在的根目录

[program:laravel_queue.js]
directory = /var/www/test
command=php artisan queue:listen --timeout=300 --tries=1
user=root
autostart=true
startsecs=2
autorestart=true
redirect_stderr=true
stopsignal=INT
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
stderr_events_enabled=false

3 supervisor的使用

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

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

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

3.1. 启动supervisord
$supervisord -c /etc/supervisord.conf
3.2. 关闭supervisord
$supervisorctl shutdown
3.3. 重新载入配置
$supervisorctl reload
3.4.更新新的配置到supervisord
$supervisorctl update
3.5.启动某个进程(program_name=你配置中写的程序名称)
$supervisorctl start program_name
3.6.查看正在守候的进程
$supervisorctl
3.7.停止某一进程 (program_name=你配置中写的程序名称)
$pervisorctl stop program_name
3.8.重启某一进程 (program_name=你配置中写的程序名称)
$supervisorctl restart program_name
3.9.停止全部进程
$supervisorctl stop all

注意:显示用stop停止掉的进程,用reload或者update都不会自动重启 。

打开web页面的监控台

设置port=65000,注意[inet_http_server]前面的注释打开,这样可以打开web页面的监控台,访问方法是http://xxx.xxx.xxx.xxx:65000

4 配置文件详细解析

=====================主配置文件========================
[unix_http_server]
file=/tmp/supervisor.sock ; UNIX socket 文件,supervisorctl 会使用
;chmod=0700 ; socket 文件的 mode,默认是 0700
;chown=nobody:nogroup ; socket 文件的 owner,格式: uid:gid ;[inet_http_server] ; HTTP 服务器,提供 web 管理界面
;port=127.0.0.1:9001 ; Web 管理后台运行的 IP 和端口,如果开放到公网,需要注意安全性
;username=user ; 登录管理后台的用户名
;password=123 ; 登录管理后台的密码 [supervisord]
logfile=/tmp/supervisord.log ; 日志文件,默认是 $CWD/supervisord.log
logfile_maxbytes=50MB ; 日志文件大小,超出会 rotate,默认 50MB
logfile_backups=10 ; 日志文件保留备份数量默认 10
loglevel=info ; 日志级别,默认 info,其它: debug,warn,trace
pidfile=/tmp/supervisord.pid ; pid 文件
nodaemon=false ; 是否在前台启动,默认是 false,即以 daemon 的方式启动
minfds=1024 ; 可以打开的文件描述符的最小值,默认 1024
minprocs=200 ; 可以打开的进程数的最小值,默认 200 ; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; 通过 UNIX socket 连接 supervisord,路径与 unix_http_server 部分的 file 一致
;serverurl=http://127.0.0.1:9001 ; 通过 HTTP 的方式连接 supervisord ; 包含其他的配置文件
[include]
files = /etc/supervisor/conf.d/*.conf ; 可以是 *.conf 或 *.ini =====================单独进程控制文件========================
[program:album_app.js]
directory = /data/album ;程序的启动目录
command=nodejs app.js ;启动命令
user = root ;启动用户
autostart=true ;在 supervisord 启动的时候也自动启动
startsecs=2 ;启动2秒后没有异常退出,就当作已经正常启动了
autorestart=true ; 程序异常退出后自动重启
redirect_stderr=true ; 把 stderr 重定向到 stdout,默认 false
stopsignal=INT
stdout_logfile=/data/logs/err.log
stderr_logfile_maxbytes=1MB ; stdout 日志文件大小,默认 50MB
stderr_logfile_backups=10 ; stdout 日志文件备份数
stderr_capture_maxbytes=1MB
stderr_events_enabled=false

参考资料

http://www.tuicool.com/articles/Ejm2u2

http://blog.csdn.net/shudaqi2010/article/details/51153961

https://my.oschina.net/crooner/blog/395069

最新文章

  1. SQL面试笔试经典题(Part 2)
  2. [转载]SQL Server如何保证可空字段中非空值唯一
  3. 【经验之谈】前端面试知识点总结(HTML相关)——附答案
  4. java:如何用代码控制H2 Database启动
  5. Boadload和Image$$??$$Limit含义
  6. Jquery-获取父级元素parent
  7. 我们都忽略了Html5的力量,如果只看成一种技术就大错特错了!
  8. linux搭建svn版本管理器
  9. BZOJ3231(矩阵连乘,稍有点复杂)
  10. CodeForces 415D Mashmokh and ACM
  11. JavaScript中把Json字符串转化为对象
  12. Travelling(spfa+状态压缩dp)
  13. Linux命令—压缩及其他
  14. 【Django】优化小技巧之清除过期session
  15. c# 读取json文件信息
  16. 点9图 Android设计中如何切图.9.png
  17. ARCSDE直连Oracle时出现错误Failed to connect to the specified server. Underlying DBMS error[ORA-12154: TNS:could not resolve the connect identifier specified. No extended error]
  18. es中的停用词
  19. How to program BMW KOMBI and NBTwith ENET E sys cable ICOM A2
  20. YQCB冲刺第二周第四天

热门文章

  1. webstrom使用
  2. win10下同时安装jdk1.7,1.8
  3. 浏览器中使用calc不识别
  4. 笨办法学Python(三十一)
  5. MySQL入门很简单: 2 MySQL数据类型
  6. ffmpeg:编解码过程,基本用法
  7. ie6下按钮下边框消失不显示的问题
  8. Buffer实例
  9. Java连接mysql中遇到的一些问题及解决方法
  10. p2597 灾难