1、安装supervisor的时候,遇到了一些问题
- 比如:
unix:///var/run/supervisor.sock no such file
unix:///var/run/supervisor.sock refused connection
pkg_resources.VersionConflict: (supervisor 4.0.4 (/usr/local/lib/python3.7/dist-packages), Requirement.parse('supervisor==3.3.1'))
……
2、解决:不用apt-get直接安装,可能是源没有supervisor 4.0.4版本
- 环境:
% lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic
% python -V
Python 3.6.8
- 步骤,注意版本号
安装python包
sudo python3.6 -m pip install supervisor==4.0.4
从git下载supervisor,解压并cd进去
wget -O supervisor-4.0.4.zip https://github.com/Supervisor/supervisor/tree/4.0.4
unzip supervisor-4.0.4.zip
cd supervisor-4.0.4
sudo python -m setup.py install
仅记一下配置
; 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
根据配置生成日志文件夹
sudo mkdir -p /var/log/supervisor/
sudo touch /var/log/supervisor/supervisord.log
好了
sudo supervisord -c /etc/supervisord.conf
sudo supervisorctl restart
3、配置队列
sudo vim /etc/supervisor/conf.d/laravel-worker.conf
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /mnt/g/Workplace/explore/php/blog/artisan queue:work --sleep=3 --tries=3 --queue=default,high
autostart=true
autorestart=true
user=kael
numprocs=8
redirect_stderr=true
stdout_logfile=/mnt/g/Workplace/explore/php/blog/storage/supervisor.log
sudo supervisord -c /etc/supervisord.conf
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel-worker:*
supervisor常用命令
supervisorctl stop program_name 停止某个进程
supervisorctl start program_name 启动某个进程
supervisorctl restart program_name 重启某个进程
sudo supervisorctl status [program_name] 查看(某个)进程
supervisorctl stop all 停止全部进程
supervisorctl reload 载入最新的配置文件,停止原有进程并按新的配置启动、管理所有进程
supervisorctl update 根据最新的配置文件,启动新配置或有改动的进程,配置没有改动的进程不会受影响而重启