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
↘️
Any other task you need to run and control simultaneously
Because Laravel wants
us to use 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
yum install epel-release -y yum install supervisor -y
vim /etc/supervisord.conf
At the very last line change *.ini into *.conf:
[include] files = supervisord.d/*.conf
cd /etc/supervisord.d/
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
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
here, two workers are running, each with numprocs=8
systemctl stop supervisord supervisorctl status supervisorctl reread supervisorctl update sudo supervisorctl restart all
.env Changes don’t have an impact after changes
Stop supervisor, and start again with php artisan config:clear
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/