Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel queues with Supervisor - Entered FATAL state, too many start retries too quickly

I'm trying to use Laravel queues with supervisor but the service is not working properly. My /var/log/supervisor/supervisord.log is:

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

My config /etc/supervisord.d/laravel-worker.conf is:

[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

When I try to restart all programs:

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

I'm a newbie with supervisor so someone can guide me?

like image 834
Alexandre Thebaldi Avatar asked Jun 18 '18 15:06

Alexandre Thebaldi


2 Answers

You need to add startsecs = 0 to your laravel-worker config like so:

[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 is default to 1s, if the program does not stay up for 1s it will see the startup as failure. Set it to 0 so the program needn’t stay running for any particular amount of time. You can check this github issue for more info: https://github.com/Supervisor/supervisor/issues/212

It would be better if you run the queue worker in daemon mode, use the --daemon flag: command=/usr/bin/php /var/www/my-project/artisan queue:work database --daemon --sleep=3 --tries=3

After you change the config file, you may need to run supervisorctl reload to allow the changes to take effect.

like image 52
DAMIEN JIANG Avatar answered Oct 19 '22 03:10

DAMIEN JIANG


Just want to share my case.

First, the user I used didn't have access to write to the log files so I added it as a sudo user.

Second, now that Supervisor can write to the error log file, I saw that there was a parse error when trying to run the PHP script. I fixed the error and now Supervisor runs the script perfectly.

Hope this helps someone too.

like image 43
Paolo Avatar answered Oct 19 '22 04:10

Paolo