How To Configuration Laravel Supervisor

  • 02-10-2022
  • 785
  • Laravel 9
  • Haresh Chauhan

When you deploy your laravel application in a live server or we can say when you start your application on production mode that time you need to keep some function running like a queue. So we need to hit a command for start queue:work for processing jobs. Sometimes queue:work process stops working or stops running on the server for a variety of many reasons, such as a exceeded worker timeout or overload server or maybe error during the perform queue job or in cash run queue:restart command.

For this reason, we need to monitor the queue:work configuration so when they stop working, exist, automatically restart itself by configuration supervision in the server.

Also, Supervision monitoring help to process the queue and allow you to run correctly on the server. So in this post, we will learn how to configure supervision on the server.

Installing Supervisor

Supervision is the process monitor for the Linux operating system, that will allow you to restart the queue: and work automatically if fails by configuring it on the server.

To install supervision on ubuntu, you may use given following suggested command.

sudo apt-get install supervisor

Configuring Supervisor

Supervision configuration files may stored n the /etc/supervisor/conf.d directory. With this given direcotry. You may create any number of configuration files that instruct suervision how to process should work and monitioring. For example let us create a file for laravel-worker.conf that file start monitoring queue:work processes.

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/forge/app.com/artisan queue:work sqs --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=forge
numprocs=8
redirect_stderr=true
stdout_logfile=/home/forge/app.com/worker.log
stopwaitsecs=3600

In cash queue:work fails it will automatically restart if fails. you can change the command option as per your desired work.

Note: You must ensure that the value of stopwaitsecs is greater than the given number of seconds consumed by your running jobs. Otherwise, Supervisor may kill the jobs before they finish processing.

Staring Supervision

Once you have done all the supervision configuration on the server, We need to update the supervision configuration on the server and start processes using the following suggest commands:

sudo supervisorctl reread

sudo supervisorctl update
    
sudo supervisorctl start laravel-worker:*

Once you press all the above-given commands it will start monitoring your queue:work jobs successfully.

Queue Laravel Command Tutorial Example


We always thanks to you for reading our blogs.


dharmesh-image

Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us

haresh-image

Haresh Chauhan

(Co-Founder)


We Are Also Recommending You :