Supervisor 筆記

1.安裝

先確保我們的系統(tǒng)安裝有 Python 環(huán)境和 pip,然后直接使用 pip 安裝即可。

$ pip install supervisor

我們可以用查看版本號的方法檢查是否成功安裝:

$ supervisord -v

使用 echo_supervisord_conf 命令可在終端打印出 Supervisor 的配置文件:

$ echo_supervisord_conf






2.使用 Supervisor 運(yùn)行 Supervisor

為了讓 Supervisor 運(yùn)行起來,我們先給它添加可執(zhí)行的程序。添加程序需要在 配置文件中添加,其路徑為:/etc/supervisor/supervisord.conf

我們用 Linux 自帶的一個簡單程序 cat 作為測試,在配置文件中添加以下部分:

# /etc/supervisor/supervisord.conf

[program:foo]
command=/bin/cat

現(xiàn)在運(yùn)行 supervisord 命令就能啟動 Supervisor。

$ sudo Supervisor

Supervisor 啟動時(shí)候會搜索默認(rèn)的配置文件路徑以讀取要配置,我們可以使用一個 -c 參數(shù)來指定配置文件路徑。

$ sudo supervisord -c /etc/supervisor/supervisord.conf

關(guān)于 Supervisor 更多的命令行參數(shù)見 官方文檔說明。






3.使用 supervisorctl 管理 Supervisor

使用 supervisorctl 命令會進(jìn)入一個 shell 控制臺,允許你控制當(dāng)前由 supervisorctl 管理的進(jìn)程。

$ sudo supervisorctl
foo                              RUNNING   pid 28646, uptime 4:26:03
supervisor>

可以看到當(dāng)前正在運(yùn)行的進(jìn)程 foo現(xiàn)在我們可以在該控制臺進(jìn)行管理操作了。

supervisorctl 參數(shù):

  • help:打印可用命令列表
supervisor> help

default commands (type help <topic>):
=====================================
add    exit      open  reload  restart   start   tail
avail  fg        pid   remove  shutdown  status  update
clear  maintail  quit  reread  signal    stop    version
  • add <name> [...]:激活一個(配置文件中配置好的)進(jìn)程或組

  • remove <name> [...]:把一個進(jìn)程或組移除已激活狀態(tài)

  • update / update all:更新,將重新加載配置文件,并更具更新后的配置文件重新啟動程序

  • update <gname> [...]:更新指定的組,參數(shù)為組名

  • clear <name> / clear all:清除進(jìn)程日志文件

  • pid / pid <name> / pid all:獲取 PID

  • reload:重啟 supervisord

  • reread:重新加載配置文件(不重啟)

  • restart <name> / restart <gname> / restart all:重啟某個進(jìn)程或全部進(jìn)程(不會重新加載配置文件)

  • start <name> / start <gname> / start all:啟動某個進(jìn)程或全部進(jìn)程

  • stop<name> / stop<gname> / stopall:暫停某個進(jìn)程或全部進(jìn)程

  • status / status <name>:打印全部或某個進(jìn)程的狀態(tài)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容