supervisor-python进程管理

supervisor官网

http://supervisord.org
文档 http://supervisord.org/installing.html

安装

1
2
3
# 使用 apt-get 会自动的在 /etc/supervisor 加入配置文件,推荐使用
apt-get install supervisor #pip install supervisor

安装好后有两个可执行文件和一些配置文件

1
2
3
4
/usr/bin/supervisord             --  supervisor服务守护进程
/usr/bin/supervisorctl -- supervisor服务控制程序,比如:status/start/stop/restart xx 等
/etc/supervisor/supervisord.conf -- 配置文件,定义服务名称以及接口等等

配置

示例,在/etc/supervisor/supervisord.conf 指定一个 getfile 的程序

1
2
3
4
5
6
7
[program:getfile]
command=python /home/zhangwei/ptest_service/app_getfile.py
directory=/home/zhangwei/ptest_service
autorstart=true
stdout_logfile=/home/zhangwei/ptest_service/log/getfile.log
stderr_logfile=/home/zhangwei/ptest_service/log/getfile_err.log

管理

1
2
3
supervisorctl status # 查看进程状态
supervisorctl status|stop|start getfile #查看 停止 启动进程

supervisord.conf文件里会发现有一段[unix_http_server]的配置,默认是9001端口,配置后,重启supervisor服务,打开浏览器输入:http://localhost:9001 可以查看相关的内容。

作者

张巍

发布于

2016-01-04

更新于

2016-01-04

许可协议

评论