jcadima
4/3/2019 - 2:16 PM

Laravel supervisor for email queueing


https://blog.whabash.com/posts/installing-supervisor-manage-laravel-queue-processes-ubuntu

https://websolutionstuff.com/post/how-to-send-e-mail-using-queue-in-laravel-7-8

https://www.bacancytechnology.com/blog/laravel-mail-example-using-markdown

https://www.youtube.com/watch?v=lgHQNkxYzMI

0) change in .env from QUEUE_CONNECTION=sync
to 
QUEUE_CONNECTION=database


* Some commands require Sudo
1) sudo apt install supervisor

2) check if its running:
service supervisor status

if supervisor is not installed, install it with:
  sudo groupadd supervisor
then check the system:
  getent group supervisor

3) add user to supervisor group:
sudo usermod -a -G supervisor your_username

4) edit config file:
sudo vim /etc/supervisor/supervisord.conf

change chmod and add chown 

-------------------------
; supervisor config file

[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0770                       ; sockef file mode (default 0700)
chown=root:supervisor

[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor            ; ('AUTO' child log dir, default $TEMP)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket

; The [include] section can just contain the "files" setting.  This
; setting can list multiple files (separated by whitespace or
; newlines).  It can also contain wildcards.  The filenames are
; interpreted as relative to this file.  Included files *cannot*
; include files themselves.

[include]
files = /etc/supervisor/conf.d/*.conf
-------------------------------------

run:
sudo service supervisor restart


5) Add a program configuration:
sudo vim /etc/supervisor/conf.d/queue.conf

[program:queue]
process_name=%(program_name)s_%(process_num)02d
command=sudo php /home/vagrant/www/nextdoor_reg/artisan queue:work --tries=3
user=root
autostart=true
autorestart=true
numprocs=1
redirect_stderr=true
stdout_logfile=/home/vagrant/www/nextdoor_reg/storage/logs/test.log


Note: Path to laravel project must match

6) Update supervisor about the new program:
sudo supervisorctl reread
supervisorctl update
supervisorctl status



alias supconfig='sudo vim /etc/supervisor/supervisord.conf'
alias supqueue='sudo vim /etc/supervisor/conf.d/queue.conf' # create this file or more for different queues
alias suprestart='sudo service supervisor restart'
alias supreread='supervisorctl reread'
alias supupdate='supervisorctl update'
alias supstatus='supervisorctl status'