supervisor安裝與使用

supervisor是python開發的linux進程管理工具,可以很方便的控制進程。

其主要的組件:

  • supervisord

是服務端程序,主要功能是啓動supervisord服務,啓動supervisor管理的子進程,對進程進行管理的服務。

  • supervisorctl

是客戶端程序,主要功能就是管理(啓動/關閉/重啓/狀態等)子進程,提供shell環境進行處理。

  • web server

Web Server主要可以在界面上管理進程,Web Server其實是通過XML_RPC來實現的,可以向supervisor請求數據,也可以控制supervisor及子進程。配置在[inet_http_server]塊裏面

  • XML_RPC

遠程調用的,上面的supervisorctl和Web Server就它實現

安裝

easy_install supervisor

測試安裝是否成功

echo_supervisord_conf

會將一個”sample” Supervisor configuration輸出到控制檯。

生成配置文件

echo_supervisord_conf > /etc/supervisord.conf

Supervisor配置文件通常命名爲supervisord.conf。 它由supervisord和supervisorctl使用。 如果任一應用程序在沒有-c選項的情況下啓動(用於顯式指示配置文件名的選項),應用程序將按照指定的順序在以下位置查找名爲supervisord.conf的文件。 它將使用它找到的第一個文件。

  1. $CWD/supervisord.conf
  2. $CWD/etc/supervisord.conf
  3. /etc/supervisord.conf
  4. /etc/supervisor/supervisord.conf (since Supervisor 3.3.0)
  5. ../etc/supervisord.conf (Relative to the executable)
  6. ../supervisord.conf (Relative to the executable)

$CWD表示運行supervisord程序的目錄。

配置進程

創建目錄:

mkdir /etc/supervisor.d

編輯/etc/supervisord.conf將最後的include註釋打開。

[include]
files=/etc/supervisor.d//*.conf

/etc/supervisor.d/目錄下創建進程配置hexo.conf

[program:hexo]
command=hexo server
directory=/opt/hexo
user=root
autostart=true
autorestart=true
stopasgroup=true
startsecs=10
startretries=999
stdout_logfile=/var/hexo/hexo.log
stdout_logfile_maxbytes=20MB
stdout_logfile_backups=10
stderr_logfile=/var/hexo/hexo_err.log
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=10

啓動

  • 啓動supervisord
supervisord -c /etc/supervisord.conf
  • 啓動supervisorctl
supervisorctl -c /etc/supervisord.conf

使用

supervisord啓動成功後,在終端輸入supervisorctl管理配置的進程。

常用命令

status --查看進程狀態
start [進程名] --啓動進程
stop [進程名] --關閉進程
restart [進程名] --重啓進程

轉載聲明:商業轉載請聯繫作者獲得授權,非商業轉載請註明出處 © wekri
原文地址:http://www.wekri.com/2018/05/19/supervisor/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章