天天看點

supervisor安裝入門使用記錄apt-get install supervisorsupervisorctl start somejobsupervisorctl stop somejob

安裝的系統版本:

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安裝:

檢視版本:

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:

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啟動程序:

停止程序:

啟動supervisor指令

-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.參考資料:

<a href="http://blog.csdn.net/orangleliu/article/details/45057377">http://blog.csdn.net/orangleliu/article/details/45057377</a>

<a href="http://supervisord.org">http://supervisord.org</a>