Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save deepak-cotocus/6b9865784dee18966e15c74ec6e487c4 to your computer and use it in GitHub Desktop.
Save deepak-cotocus/6b9865784dee18966e15c74ec6e487c4 to your computer and use it in GitHub Desktop.
Laravel Queue Supervisor configuration

How to use Supervisor:A Process Control System for Laravel queue In Linux based OS

What is Supervisor: A Process Control System?

Supervisor is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems. Supervisor provides you with one place to start, stop, and monitor your processes. Processes can be controlled individually or in groups. You can configure Supervisor to provide a local or remote command line and web interface.


Why do we use Supervisor for Larave Queue?

The supervisor is a process manager which Laravel suggests to use as a process monitor for queue workers. It will automatically start the queue worker in the background, even after the system has booted and will automatically restart the worker if the worker exits unexpectedly.


Steps to Install a Supervisor: A Process Control System for my Laravel Application in Linux based OS.

STEP 1:

Installing Supervisor

Run sudo apt-get install supervisor to install Supervisor

Run service supervisor status to check server is running after installation

supervisor2

STEP 2:

Configuring Supervisor

  • Supervisor configuration files are typically stored in the /etc/supervisor/conf.d directory
  • Within this directory, you may create any number of configuration files that instruct supervisor how your processes should be monitored
  • For example, let's create a mhn-queue.conf file that starts and monitors a queue:work process:

Go to /etc/supervisor

Run ls to cross check the conf.d directory and create your own process file under this directory.

supervisor3

STEP 3:

Let’s consider an example.

Go to /etc/supervisor/conf.d directory and create mhn-queue.conf

To Create mhn-queue.conf run touch mhn-queue.conf

STEP 4:

Open mhn-queue.conf in Vi editor and Write the below code.

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

supervisor4


NOTE: change the queue:work database portion of the command directive to reflect your desired queue connection. It could be Redis, sqs in youre application. You can check it in config/queue.php


STEP 5:

Starting Supervisor

Once the configuration file has been created, you may update the Supervisor configuration and start the processes using the following commands:

Run below commands

  • sudo supervisorctl reread
  • sudo supervisorctl update
  • sudo supervisorctl start mhn-queue:*

Referance:

Have a great learning...☺️


@jaydipsinhparmar
Copy link

@pvdptje
Copy link

pvdptje commented Mar 25, 2024

Thank you.

I had an error while following these steps.
The cause was because my PHP is managed on a user level on the webhost, and I had to use the full path in the config file.

/var/www/vhosts/example.com/.phpenv/shims/php /var/www/vhosts/example.com/artisan queue:work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment