supervisor安装入门使用记录

安装的系统版本:
root@iZbp1eazisi1qi938qwctmZ:~# cat /proc/version
Linux version 4.4.0-79-generic (buildd@lcy01-30) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #100-Ubuntu SMP Wed May 17 19:58:14 UTC 2017

1.安装supervisor
Ubuntu可以直接通过apt安装:

apt-get install supervisor

查看版本:
root@iZbp1eazisi1qi938qwctmZ:/apptest/supervisortest/shdir# supervisord -version
3.2.0

2.给我们自己开发的应用程序编写一个配置文件,让supervisor来管理它。每个进程的配置文件都可以单独分拆,放在/etc/supervisor/conf.d/目录下,以.conf作为扩展名

root@iZbp1eazisi1qi938qwctmZ:~# cd /etc/supervisor/conf.d/
root@iZbp1eazisi1qi938qwctmZ:/etc/supervisor/conf.d# ll
total 16
drwxr-xr-x 2 root root 4096 Jun 19 19:55 ./
drwxr-xr-x 3 root root 4096 Jun 19 17:41 ../
-rw-r--r-- 1 root root 129 Jun 19 17:02 app.conf
-rw-r--r-- 1 root root 318 Jun 19 17:15 somjob.conf

例如:somejob文件

[program:somejob]
command=/usr/bin/python /apptest/supervisortest/shdir/somejob.py
directroy=/apptest/supervisortest/shdir
autostart=true
autorestart=true
startretries=3
user=root
stdout_logfile=/apptest/supervisortest/shdir/%(program_name)s.log
stderr_logfile=/apptest/supervisortest/shdir/%(program_name)s.logmejob

command脚本文件目录结构:
root@iZbp1eazisi1qi938qwctmZ:/apptest/supervisortest/shdir# ll
total 320
drwxr-xr-x 2 root root 4096 Jun 19 17:20 ./
drwxr-xr-x 4 root root 4096 Jun 19 15:35 ../
-rw-r--r-- 1 root root 306803 Jun 20 14:04 somejob.log
-rw-r--r-- 1 root root 0 Jun 19 17:16 somejob.logmejob
-rwxrwxrwx 1 root root 335 Jun 19 17:05 somejob.py*

command脚本:
import sys, time
while True:

print "pyserver runing %s"%time.ctime()
sys.stdout.flush()
time.sleep(10)

3.supervisord.conf设置
增加读取配置脚本
[include]
files = /etc/supervisor/conf.d/*.conf

还可增加web server访问端口,不过好像没生效(本地机器可以访问到index.html),分号表示注释
[inet_http_server]
; Web管理界面设定
port=9001
;username = admin
;password = 123

4.启动停止进程命令:
重启supervisor,让配置文件生效,然后运行命令supervisorctl启动进程:

supervisorctl start somejob

停止进程:

supervisorctl stop somejob

  1. 启动supervisor命令
  2. -n -c /etc/supervisor/supervisord.conf

6.启动完成后查看进程
root@iZbp1eazisi1qi938qwctmZ:~# ps -ef|grep super
root 22393 1 0 Jun19 ? 00:00:15 /usr/bin/python /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
root 22753 22393 0 Jun19 ? 00:00:01 /usr/bin/python /apptest/supervisortest/shdir/somejob.py
root 24317 24249 0 13:51 pts/0 00:00:00 grep --color=auto super
root@iZbp1eazisi1qi938qwctmZ:~#

7.参考资料:
http://blog.csdn.net/orangleliu/article/details/45057377
http://supervisord.org

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值