Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

[SOLVED] Laravel : Supervisor FATAL/BACKOFF Exited too quickly (process log may have details)

Table of Contents

Problem

I’m trying to use Laravel queues with a supervisor but the service is not working properly.

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)

When I try to check status:
$ sudo supervisorctl status
$ laravel-worker:laravel-worker_00: BACKOFF Exited too quickly (process log may have details)
$ laravel-worker:laravel-worker_00: BACKOFF Exited too quickly (process log may have details)

Solution

In my case, the supervisor was exiting very fast because it was finishing before the startsecs and since startsecs wasn’t defined, it uses the default which is 1.

Setting startsecs=0 fixed my issue.

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 a 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.