天天看點

關于supervisor的入門指北

關于supervisor的入門指北

在目前這個時間點(2017/07/25),supervisor還是僅支援python2,是以我們要用版本管理pyenv來隔離環境。

pyenv

根據官方文檔的講解,pyenv的主要思路是修改環境變量,将想要用的那個版本的路徑插到環境變量中的最前面去。

下載下傳安裝的話,直接

curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash

然後再根據自己的需求去用

pyenv install xxxxx

來安裝想要用的版本。

關于使用方面,

pyenv local 2.7.13

,就是指在本目錄内,用python2這個解釋器。

pyenv global 2.7.13

就是全局了。

supervisor

根據上文安裝好pyenv後,建立一個檔案夾

py2-supervisor

,然後在這個檔案内聲明

pyenv local 2.7.13

,接着

pip install supervisor

,安裝完後輸入

echo_supervisord_conf

,如果能看到配置資訊就是安裝成功了。

先生成預設的配置檔案

echo_supervisord_conf > /etc/supervisor/supervisor.conf

,然後在這個目錄下再建立一個

conf.d/

的檔案夾,在這裡面放我們具體的程式的配置檔案。

如建立一個

gunicron.ini

檔案,具體配置如下

[program:gunicorn]
directory = /home/nan/code/novel_site/mysite
command = gunicorn -c gunicorn.conf.py mysite.wsgi
autostart = true
redirect_stderr = true
stdout_logfile_maxbytes = 20MB
stdout_logfile_backups = 20
stdout_logfile = /home/log/gunicorn-supervisor.log
           

在主配置檔案

supervisor.conf

中導入這個檔案夾下的配置檔案

[includes]
files = ./conf.d/*ini
           

完成之後,在

py2-supervisor

檔案夾下

supervisor -c /etc/supervisor/supervisor.conf

就可以跑起來了

supervisorctl

按上述那樣運作的話,supervisor會在背景跑起來,這個時候我們可以用互動模式來通路

supervisorctl -c supervisor.conf

,進入互動模式後,就可以用

start stop restart

這種非常人性化地去操作我們的相關任務