How to Configure supervisord on Linux for Laravel Jobs Queue

This quick tutorial help to configure Supervisor with Lumen application on Linux.I have already shared tutorial about Queue and Run Jobs using worker in Lumen/Laravel Framework.

Supervisor is a process monitor for the Linux operating system, which will automatically restart your jobs queue using queue:listen or queue:work commands if they fail. You can install Supervisor on Ubuntu using following command,

sudo apt-get install supervisor

supervisord is a simple, fast work queue and designed for reducing the latency of page views in high-volume web applications by running time-consuming tasks asynchronously.

I am assuming you read my previous tutorial that help to install Beanstalkd on linux and download package on lumen application.I am extending this tutorials and configure supervisord for run queue jobs as daemon process.

You can also check other recommended tutorials of Lumen/Laravel,

Step 1: Install supervisor on Linux using below command, if already installed please skip this step.
sudo apt-get install supervisor

Step 2: Kill supervisor process if already running, if not skip this step.

ps aux | grep supervisor //get supervisor running process
kill -9 pid //kill process

Supervisor configuration files are stored in the /etc/supervisor/conf.d directory.You can create number of configuration file for each process.I will create new test_bq.conf file using below command.

sudo vi /etc/supervisord.d/test_bq.conf

Now added below script into this file,

[program:test-backend_queue]
command=sudo -u root php artisan queue:work --daemon --env=dev --tries=1 --queue=default,onboarding
directory=/usr/share/nginx/www/test-lumen
stdout_logfile=/usr/share/nginx/www/test-lumen/app/test-backend_supervisord.log
redirect_stderr=true
numprocs=10
process_name=%(program_name)s_%(process_num)02d
autostart=true
;user=abc
autorestart=true

Step 3: Now We will edit /etc/supervisor.conf file and paste below code into this file.

[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10           ; (num of main logfile rotation backups;default 10)
loglevel=info                ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false               ; (start in foreground if true;default false)
minfds=1024                  ; (min. avail startup file descriptors;default 1024)
minprocs=200                 ; (min. avail process descriptors;default 200)
;umask=022                   ; (process file creation umask;default 022)
;user=abc                 ; (default is current user, required if root)
;identifier=supervisor       ; (supervisord identifier, default is 'supervisor')
directory=/tmp              ; (default is not to cd during start)
;nocleanup=true              ; (don't clean up tempfiles at start;default false)
;childlogdir=/tmp            ; ('AUTO' child log dir, default $TEMP)
;environment=KEY="value"     ; (key value pairs to add to environment)
;strip_ansi=false            ; (strip ansi escape codes in logs; def. false)
 
 
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
 
 
[unix_http_server]
file=/tmp/supervisor.sock
chmod=0755 ; sockef file mode (default 0700)
 
[inet_http_server]
port=127.0.0.1:9005
;username=abc
 
[supervisorctl]
;srevreurl=http://127.0.0.1:9001
serverurl=unix:///tmp/supervisor.sock
;username=abc
;serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket
 
[include]
files = /etc/supervisord.d/*.conf

Step 4: Now Start supervisord using below command.

sudo supervisord -c /etc/supervisord.conf

Additional Supervisor Command

sudo supervisorctl reread //read supervisord configuration file
sudo supervisorctl update //update supervisord if anything changed in configuration file

5 thoughts on “How to Configure supervisord on Linux for Laravel Jobs Queue

Leave a Reply

Your email address will not be published. Required fields are marked *