In this KB
- What is Supervisord
- How to Install Supervisord and use it in Laravel web apps
- How to view job status
This guide will assist you in learning about Supervisord and how you could install it for your Laravel applications.
What is Supervisord?
Supervisord is a simple, fast worker manager, designed to monitor and control the processes which allows you to defer the processing of a time consuming task to speed up the web requests to your application.
Note: Supervisord is only available with Laravel Applications. You need a Laravel application installed on your server for using Supervisord.
Step 1: Installing Supervisord
Go to Server Management, then Settings & Packages, and then access the Packages section. Click on the Install button next to Supervisord to start the installation process.
Before the process starts, you will be asked to install Redis on the server (if it is not already installed), as it is required for Laravel queues. Wait for the installation process to finish.
Note: You can check Supervisord service status from Manage Services section, and also Restart the service, if required.
Step 2: Supervisord Application Prerequisites
Note: This process describes the configuration when Redis is used as the default driver. You need to configure your application to use Redis.
After installation, you need to carry out application configuration changes so that Redis could be used as the queue driver. To do that, first it is required to install predis/predis package for Laravel with Composer.
Connect to server via SSH terminal, then go to your application directory webroot (/home/master/applications/<app folder>/public_html/) and run this command:
composer require predis/predis
Once it is installed, next you need to configure it in the application. For that, edit the /home/master/applications/public_html/.env file in your application as follows:
Change From: QUEUE_DRIVER=sync
Change to: QUEUE_DRIVER=redis
Next, edit the /home/master/applications/public_html/config/queue.php file as follows:
Change From: ‘default’ => env(‘QUEUE_DRIVER’, ‘sync’),
Change To: ‘default’ => env(‘QUEUE_DRIVER’, redis’),
After these changes are saved in the Laravel application, proceed to the next step.
Step 3: Add New Job
Under Application Management, go to Application Settings and select the tab for Supervisor Jobs. Click on Add New Job button to add a job for Supervisord.
The various Laravel queue related options are briefly explained below:
Connection Driver: Redis is used as the queue driver where the jobs will be held as configured in Step 2.
Number of process: Number of processes control how many processes supervisord will run at the same time. The default value is 1.
Timeout: The timeout option specifies how long the Laravel queue master process will wait before killing off a child queue worker that is processing a job.
Sleep Time: Sleep time option determines how long the worker will “sleep” if there are no new jobs available. While sleeping, the worker will not process any new jobs – the jobs will be processed after the worker wakes up again.
Queue: The names of the queues to work
Maximum Tries: Maximum number of tries after which the job is logged as a fail
Environment (Optional): The environment the command should run under
Fill in the required details and click the Save button.
Note: Once a job has been created, Supervisord will use the platform default Artisan path which should be /home/master/applications/public_html/artisan
Step 4: Job Status and other options
The job status can be checked by clicking the Jobs Status button.
This will show the status of job and other related information including uptime.
If you want to restart any job, click the icon in front of it. There is also the option of removing any job by clicking the remove icon.
Note: You can check the job logs in the following path: /home/master/applications/<app folder>/logs/<appname_jobID>.log
You now know how to install and use Supervisord on Cloudways with your Laravel app.