python进程管理工具supervisor使用实例

WBOY
Release: 2016-06-06 11:33:05
Original
1814 people have browsed it

平时我们写个脚本,要放到后台执行去,我们怎么做呢?

代码如下:


nohup python example.py 2>&1 /dev/null &

用tumx或者screen? 但是用着可能都不爽,今天就看看python里面的一个进程管理工具supervisor:

官方说:Supervisor: A Process Control System

说白了他就是一个demon程序,他来帮助我们完成对我们想要托管的脚本也好程序也好,好好的照料;

1、安装

python的东西就是好安装,如果是centos系列,可以使用:

代码如下:


yum install supervisor


如果是debin系列的:

代码如下:


apt-get install supervisor

或者干脆点:

代码如下:


easy_install supervisor
pip install supervisor

2、创建配置文件

你可以使用自带的一个工具:echo_supervisord_conf
默认是在/etc下 创建,但需要你有root权限:

代码如下:


echo_supervisord_conf > /etc/supervisord.conf


当然也可以是其它目录,但需要在启动的时候指定(-c)

3、启动Supervisor

接下来我们来看看怎么启动supervisord 和 supervisorctl

首先找一个要托管的程序,比如/bin/date

代码如下:


vim /etc/supervisord.conf

[program:test]
command=python /root/test_supervisor.py
process_name=%(program_name)s
stdout_logfile=/root/test.log
stderr_logfile=/root/test.log


保存,启动:

代码如下:


/usr/bin/supervisord -c /etc/supervisord.conf

发送信号:

肿么样,很爽吧,接下来,就可以自由发挥了。。。
http://supervisord.org/ 这是官网。
最后的最后,他还可以界面管理哦,这也为我们在界面进行进程管理提供了一种方法哦!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!