supervisord安裝使用簡記


What is supervisor

Supervisor is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems.

引用自supervisor官網,中文意思就是是一個C/S架構的系統,用來監控管理類UNIX系統上進程。

Features

簡單,高效,可擴展,兼容性好(Orz,其實不能在windows上用)

想看更多請去官網

Installing

  1. 因為是用Python實現的,所以最簡單的方式是pip install supervisor
  2. ubuntu系統上也可以直接使用sudo apt-get install supervisor

Configure

  • 使用 echo_supervisord_conf 就可以看到默認的配置文件,如下:
➜  Log echo_supervisord_conf  
; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
;
; Notes:
;  - Shell expansion ("~" or "$HOME") is not supported.  Environment
;    variables can be expanded using this syntax: "%(ENV_HOME)s".
;  - Comments must have a leading space: "a=b ;comment" not "a=b;comment".
  • 配置文件

使用 echo_supervisord_conf > /etc/supervisord.conf命令將配置文件保存在xx下面,然后修改配置文件。推薦的方式是將最后一行修改到某個固定文件夾,如下:

[include]
files = /etc/supervisord.d/*.ini

這樣每次運行都會加載此目錄下的配置文件,每個文件單獨管理一個進程。而*.ini的內容一般如下:

配置1
[program:simpleserver]
command=python -m SimpleHTTPServer  # 執行的命令 ,若是虛擬環境則需要注意命令的路徑,見配置2
directory=/home/wang/Downloads  # 執行命令的路徑
user=wang  #  執行命令的用戶
autorestart=true  # 出錯后自動重啟
redirect_stderr=true  # 錯誤日志重定向
stdout_logfile=/home/wang/Log/SimpleHTTPServer.log  # 日志的路徑
loglevel=info  # 日志的級別
配置2
[program:hongbaoyun]
command=/home/wang/.virtualenvs/xxx-virtual-env/bin/python manage.py runserver 0.0.0.0:9999  # 此處python位置是virtualenv中python的位置
directory=/home/wang/Workspace/khb/hongbaoyun
user=wang

Run

  • 啟動
    supervisord -c supervisord.conf # 指定配置文件啟動supervisord

  • 啟動spuervisordctl
    supervisordctl

  • supervisordctl常用命令

supervisorctl stop program_name  # 停止某一個進程,program_name 為 [program:x] 里的 x

supervisorctl start program_name  # 啟動某個進程

supervisorctl restart program_name  # 重啟某個進程

supervisorctl stop groupworker:  # 結束所有屬於名為 groupworker 這個分組的進程 (start,restart 同理)

supervisorctl stop groupworker:name1  # 結束 groupworker:name1 這個進程 (start,restart 同理)

supervisorctl stop all  # 停止全部進程,注:start、restartUnlinking stale socket /tmp/supervisor.sock
、stop 都不會載入最新的配置文件

supervisorctl reload  # 載入最新的配置文件,停止原有進程並按新的配置啟動、管理所有進程

supervisorctl update  # 根據最新的配置文件,啟動新配置或有改動的進程,配置沒有改動的進程不會受影響而重啟
  • 圖行管理界面

在配置文件中去掉 [inet http server]的注釋就可在瀏覽器中通過127.0.0.1:8000中看到圖形管理界面

FAQ

Refer


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM