Laravel排队与Supervisor - 进入FATAL状态,太多开始重试太快

时间:2018-06-18 15:06:20

标签: laravel supervisord supervisor

我尝试将Laravel队列与主管一起使用,但服务无法正常运行。我的/var/log/supervisor/supervisord.log是:

2018-06-18 10:56:07,441 INFO spawned: 'laravel-worker_00' with pid 20838
2018-06-18 10:56:07,446 INFO spawned: 'laravel-worker_01' with pid 20839
2018-06-18 10:56:08,021 INFO exited: laravel-worker_01 (exit status 255; not expected)
2018-06-18 10:56:08,033 INFO gave up: laravel-worker_01 entered FATAL state, too many start retries too quickly
2018-06-18 10:56:08,033 INFO exited: laravel-worker_00 (exit status 255; not expected)
2018-06-18 10:56:09,034 INFO gave up: laravel-worker_00 entered FATAL state, too many start retries too quickly

我的配置/etc/supervisord.d/laravel-worker.conf是:

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=/usr/bin/php /var/www/my-project/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
user=root:root
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/my-project/worker.log

当我尝试重启所有程序时:

$ sudo supervisorctl restart all
$ laravel-worker:laravel-worker_00: ERROR (abnormal termination)
$ laravel-worker:laravel-worker_01: ERROR (abnormal termination)

我是主管的新手所以有人可以指导我吗?

2 个答案:

答案 0 :(得分:6)

您需要像这样将startsecs = 0添加到laravel-worker的配置中:

[program:laravel-worker]     
process_name=%(program_name)s_%(process_num)02d
command=/usr/bin/php /var/www/my-project/artisan queue:work --sleep=3 --tries=3
.....
startsecs = 0

startsecs默认为1s,如果程序没有保持1s,它将启动视为失败。将其设置为0,这样程序就不必在任何特定时间内保持运行状态。您可以查看此github问题以获取更多信息:https://github.com/Supervisor/supervisor/issues/212

如果在守护程序模式下运行队列工作器,则最好使用--daemon标志:command=/usr/bin/php /var/www/my-project/artisan queue:work database --daemon --sleep=3 --tries=3

更改配置文件后,可能需要运行supervisorctl reload才能使更改生效。

答案 1 :(得分:1)

只想分享我的情况。

首先,我使用的用户无权写入日志文件,因此我将其添加为sudo用户。

第二,现在Supervisor可以写入错误日志文件了,我看到尝试运行PHP脚本时出现了解析错误。我更正了错误,现在Supervisor可以完美地运行脚本了。

希望这也会对某人有所帮助。