supervisor
UNIX-based process monitoring & control
* the following experience was with CentOS 7.3 and Supervisor 3.4
Mayeenul Islam
UX Designer & PHP Developer
mayeenulislam@github.io
Onboarding
↘️
If your application has Laravel Jobs using Queue
Why Supervisor
↘️
Any other task you need to run and control simultaneously
Because Laravel wants
us to use Supervisor
Why Supervisor
In production, you need a way to keep your queue:work processes running. A queue:work process may stop running for a variety of reasons, such as an exceeded worker timeout or the execution of the queue:restart command.
〞
There is one main advantage of the Supervisor that the task you set there is working constantly. ...when the process will finish the new one will starts immediately. Crontab runs every process for a minute minimum!
So if you have a task like queue:work is much better to use Supervisor over Crontab.
– Conrad Anker
supervisord vs. crontab
yum install epel-release -y yum install supervisor -y
Installation
vim /etc/supervisord.conf
Configuration: Global
At the very last line change *.ini into *.conf:
[include] files = supervisord.d/*.conf
cd /etc/supervisord.d/
Configuration: Worker
Create laravel-worker.conf and edit with the following content:
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/myproject/artisan queue:work --daemon --sleep=3 --tries=3
autostart=true
autorestart=true
numprocs=8
user=apache
redirect_stderr=true
stderr_logfile=/var/www/html/myproject/storage/logs/supervisord-error.log
stdout_logfile=/var/www/html/myproject/storage/logs/supervisord.log
Configuration: Worker
laravel-worker.conf
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/myproject/artisan queue:work --daemon --sleep=3 --tries=3
autostart=true
autorestart=true
numprocs=8
user=apache
redirect_stderr=true
stderr_logfile=/var/www/html/myproject/storage/logs/supervisord-error.log
stdout_logfile=/var/www/html/myproject/storage/logs/supervisord.log
Worker name
(cannot contain space or special char)
Your command
Number of Concurrent Processes per command
Appropriate user
Log location
systemctl start supervisord systemctl enable supervisord systemctl status supervisord
Starting
Status
here, two workers are running, each with numprocs=8
systemctl stop supervisord supervisorctl status supervisorctl reread supervisorctl update sudo supervisorctl restart all
Necessary Commands
Meaningful Logs
.env Changes don’t have an impact after changes
Stop supervisor, and start again with php artisan config:clear
Known Issues
Queue Jobs don’t have access to Session
This particular one is actually related to Events, not to the Supervisor. So don’t read any listener data from Session. Language and active user data won’t be available if read from the session
APP_URL = localhost
Supervisor reads APP_URL from the .env. So make sure the site's absolute root URL is mentioned there
systemctl stop supervisord yum remove supervisor rm –rf /etc/supervisord.d/
Uninstallation
-
.env Cached
https://stackoverflow.com/a/54029293/1743124 -
Install & Configure Supervisor on CentOS 7 - Fit DevOps
https://fitdevops.in/install-and-configure-supervisor-on-centos-7/ - How to Install and Manage Supervisor on Ubuntu and Debian VPS
https://www.digitalocean.com/community/tutorials/how-to-install-and-manage-supervisor-on-ubuntu-and-debian-vps - StackExchange Resources
- Supervisor Documentation
http://supervisord.org/ - Laravel Resources
https://laravel.com/docs/9.x/queues#supervisor-configuration
Resources
Let's Supervise
Supervisor
By Mayeenul Islam
Supervisor
Introduction to the Supervisor - a UNIX-based process monitoring & control tool
- 188