supervisor安装入门使用记录

    xiaoxiao2023-07-23  166

    安装的系统版本:root@iZbp1eazisi1qi938qwctmZ:~# cat /proc/versionLinux 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.安装supervisorUbuntu可以直接通过apt安装:

    apt-get install supervisor

    查看版本:root@iZbp1eazisi1qi938qwctmZ:/apptest/supervisortest/shdir# supervisord -version3.2.0

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

    root@iZbp1eazisi1qi938qwctmZ:~# cd /etc/supervisor/conf.d/root@iZbp1eazisi1qi938qwctmZ:/etc/supervisor/conf.d# lltotal 16drwxr-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.pydirectroy=/apptest/supervisortest/shdirautostart=trueautorestart=truestartretries=3user=rootstdout_logfile=/apptest/supervisortest/shdir/%(program_name)s.logstderr_logfile=/apptest/supervisortest/shdir/%(program_name)s.logmejob

    command脚本文件目录结构:root@iZbp1eazisi1qi938qwctmZ:/apptest/supervisortest/shdir# lltotal 320drwxr-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, timewhile 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

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

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

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

    相关资源:敏捷开发V1.0.pptx
    最新回复(0)