文章出處

服務器版本 Ubuntu 16.04 LTS。

Supervisor 是一個用 Python 寫的進程管理工具,可以很方便的對進程進行啟動、停止、重啟等操作。

安裝命令:

$ apt-get install supervisor

安裝成功后,會在/etc/supervisor目錄下,生成supervisord.conf配置文件。

你也可以使用echo_supervisord_conf > supervisord.conf命令,生成默認的配置文件(不建議,內容比較多)。

supervisord.conf示例配置:

; supervisor config file

[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0700                       ; sockef file mode (default 0700)

[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor            ; ('AUTO' child log dir, default $TEMP)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket

; The [include] section can just contain the "files" setting.  This
; setting can list multiple files (separated by whitespace or
; newlines).  It can also contain wildcards.  The filenames are
; interpreted as relative to this file.  Included files *cannot*
; include files themselves.

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

進程配置會讀取/etc/supervisor/conf.d目錄下的*.conf配置文件,我們在此目錄下創建一個hwapp.conf進程配置文件:

[program:hwapp]
directory=/root/wwwroot/hwapp/publish
command=dotnet hwapp.dll
autostart=true
autorestart=true
startretries=10
redirect_stderr=true
stdout_logfile=/root/wwwroot/hwapp/hwapp.log
environment=ASPNETCORE_ENVIRONMENT="Development"

需要注意的是,如果不是root賬號,需要對這些目錄進行權限設置,要不然會報一些錯誤(一定要在 root 賬號下進行配置,要不然一系列權限引起的問題😂)。

$ sudo chmod 777 /var/run
$ sudo chmod 777 /etc/supervisor

接著就可以啟動 Supervisord 了:

$ supervisord

supervisorctl 常用命令:

命令 說明
supervisorctl stop program_name 停止某個進程
supervisorctl start program_name 啟動某個進程
supervisorctl restart program_name 重啟某個進程
supervisorctl stop all 停止全部進程
supervisorctl reload 載入最新的配置文件,停止原有進程并按新的配置啟動、管理所有進程
supervisorctl update 根據最新的配置文件,啟動新配置或有改動的進程,配置沒有改動的進程不會受影響而重啟

參考資料:


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()