Supervisor is a great tool to guarantee that your worker process is always running, even if it closes due to failure.
# Ubuntu
sudo apt install supervisor
# Centos
sudo yum install supervisorSupervisor configuration files typically live in:
/etc/supervisor/conf.d(Ubuntu)/etc/supervisord.d(Centos)
Create a new messenger-worker.conf (Ubuntu) or messenger-worker.ini (Centos) file there to make sure that 2 instances of messenger:consume are running at all times:
;/etc/supervisor/conf.d/messenger-worker.conf
[program:messenger-consume]
command=php /path/to/your/app/bin/console messenger:consume async --time-limit=3600
user=ubuntu
numprocs=2
startsecs=0
autostart=true
autorestart=true
process_name=%(program_name)s_%(process_num)02d
Options:
[program:messenger-consume]- name for the workeruser- run command on behalf of this userstdout_logfile=/var/log/worker.log- output to fileautostart=true- start worker with supervisorautorestart=true- autorestart worker on failurenumprocs=2- number of instances of this worker
sudo supervisorctl reread
sudo supervisorctl update
# Add supervisor to autoload on the system boot
systemctl enable supervisord
# Restart supervisor
sudo service supervisor restart
# Run all processes inside the group "messenger-consume"
sudo supervisorctl start messenger-consume:*Run this command to tell supervisor to stop these workers:
sudo supervisorctl stop messenger-consume:*