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, and 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.

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,

command=sudo -u root php artisan queue:work --daemon --env=dev --tries=1 --queue=default,onboarding

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

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 pidfile;default
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)
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
chmod=0755 ; sockef file mode (default 0700)
;serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket
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

  • Or you can use

    nohup php artisan queue:work &

    To keep listening the queue in background.

    • yes, but supervisor is better idea to run process in background.