supervisor使用報錯解決

好名字可以让你的朋友更容易记住你發表於2024-10-17

常用命令

supervisorctl status 檢視狀態
supervisorctl reload 重新載入配置檔案
supervisorctl start all/ftp 啟動所有/指定的程式程序
supervisorctl stop all/frp 關閉所有/指定的程式程序

一.簡化後的supervisord.conf配置檔案內容:

[unix_http_server]
file=/var/run/supervisor/supervisor.sock   ; (the path to the socket file)

[supervisord]
logfile=/var/log/supervisor/supervisord.log  ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB       ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10          ; (num of main logfile rotation backups;default 10)
loglevel=info               ; (log level;default info; others: debug,warn,trace)
pidfile=/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false              ; (start in foreground if true;default false)
minfds=1024                 ; (min. avail startup file descriptors;default 1024)
minprocs=200                ; (min. avail process descriptors;default 200)

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

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

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

 注意 所有需要用supervisor管理的服務放在/etc/supervisor.d/目錄下;

supervisor開機自啟

1、首先執行命令:systemctl is-enabled supervisord ,結果如下圖:提示尚未為supervisor配置開機啟動

2、在shell裡執行 vim /lib/systemd/system/supervisord.service 編輯開機啟動時執行的指令碼如下

[Unit]
Description=Process Monitoring and Control Daemon
After=rc-local.service

[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
RuntimeDirectory=supervisor
RuntimeDirectoryMode=755

[Install]
WantedBy=multi-user.target

注意:ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf 一定要這樣寫,supervisor安裝完預設會在/etc/supervisord.conf 產生

啟動程式

systemctl enable supervisord

驗證一下是否為開機啟動:

systemctl is-enabled supervisord

二. “supervisor.sock no such file”的解決方法

1:去/run/supervisor中touch一個supervisor.sock檔案 並chmod 777 supervisor.sock
2:kill 掉所有之前的supervisor程序
3:啟動supervisor

<!--啟動-->
systemctl start supervisor

supervisord -c /etc/supervisord.conf

<!--關閉-->
systemctl stop supervisor

重新啟動supervisor

三:Error: Cannot open an HTTP server: socket.error reported errno.ENOENT (2)

supervisord -c /etc/supervisord.conf 啟動時報錯

Error: Cannot open an HTTP server: socket.error reported errno.ENOENT (2)
For help, use /usr/bin/supervisord -h

原因,預設配置的目錄不存在, 手動建立一個就好了**mkdir /run/supervisor**

四: Unlinking stale socket /tmp/supervisor、unix:/run/supervisor/supervisor.sock no such file

supervisor出現Unlinking stale socket /tmp/supervisor、unix:/run/supervisor/supervisor.sock no such file。遇到以上類似的問題,可以透過以下步驟得到解決。

1、修改配置檔案

vim supervisord.conf
這裡把所有的/tmp路徑改掉

/tmp/supervisor.sock 改成/var/run/supervisor.sock,
/tmp/supervisord.log 改成/var/log/supervisor.log,
/tmp/supervisord.pid 改成 /var/run/supervisor.pid 要不容易被linux自動清掉。

樣例如下:

[unix_http_server]
file=/var/run/supervisor/supervisor.sock ; the path to the socket file

[supervisord]
logfile=/var/log/supervisord.log ; main log file; default $CWD/supervisord.log

pidfile=var/run/supervisor/supervisord.pid ; supervisord pidfile; default supervisord.pid

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

2、修改許可權

sudo chmod 777 -R /run
sudo chmod 777 -R /var

如果沒改,啟動可能會報錯 IOError: [Errno 13] Permission denied: ‘/var/log/supervisord.log’

3、建立supervisor.sock

sudo touch /var/run/supervisor/supervisor.sock
sudo chmod 777 /var/run/supervisor/supervisor.sock
sudo chmod 777 -R /var/run

4、新增supervisor.sock連結

unlink /var/run/supervisor/supervisor.sock

5、啟動supervisord

注意stop之前的例項或殺死程序

supervisord
或者
supervisord -c /home/Nox/conf/nox/supervisord.conf

五:Exited too quickly (process log may have details)

使用supervisor監控程式檢視狀態總是報Exited too quickly (process log may have details)

報這個錯的原因很簡單,用supervisor監控程式,但是使用的是自己的方法啟動程式,那當然不會監控成功,正確的做法是用supervisor重啟。

六:unix:///run/supervisor/supervisor.sock refused connection

此時正確的做法是,應該重新指定配置檔案,這樣就能正確的生成一個sock檔案

supervisord -c /etc/supervisord.conf

相關文章