导语
代码部分完成后,接下来是配置 Supervisor,用来进程守护。当队列意外停止后,Supervisor 可以重启进程,保证队列的稳定运行。
安装以及配置
- 依次执行
yum install python-setuptools
、easy_install supervisor
进行安装 - 创建
/etc/supervisor/
目录,并生成默认配置文件
- 参考 Homestead 中
supervisor.conf
文件进行修改,最终如下
[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod=0700 ; socket file mode (default 0700)
;[inet_http_server] ; inet (TCP) server disabled by default
;port=127.0.0.1:9001 ; (ip_address:port specifier, *:port for all iface)
;username=user ; (default is no username (open server))
;password=123 ; (default is no password (open server))
[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=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
[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
[include]
files = /etc/supervisor/conf.d/*.conf
- 创建
/etc/supervisor/conf.d
目录,配置laravel-worker.conf
文件如下
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /usr/local/nginx/html/myLaravel/artisan queue:work
autostart=true
autorestart=true
user=www-data
numprocs=2
redirect_stderr=true
stdout_logfile=/var/log/supervisor/laravel-worker.log
启动
-
supervisord -c /etc/supervisor/supervisor.conf
启动服务 - 依次执行
supervisorctl reread
、supervisorctl update
、supervisorctl start laravel-worker:*
一个插曲,有报错 error:
,最终的解决办法是带上配置文件 supervisorctl -c /etc/supervisor/supervisor.conf reread
- 查看一下状态
状态正常,测试结果也是正常的。