Skip to content

Instantly share code, notes, and snippets.

@Pezhvak
Last active April 7, 2020 10:43
Show Gist options
  • Save Pezhvak/a1db082228e7f8939f9f3b4416799906 to your computer and use it in GitHub Desktop.
Save Pezhvak/a1db082228e7f8939f9f3b4416799906 to your computer and use it in GitHub Desktop.
Supervisor CentOS Installation (Laravel)

alright, everybody writen one about this but nothing worked for me, here's how it works without any problem:

first run yum install supervisor

supervisor searches for configuration file in following paths: /usr/local/etc/supervisord.conf, /usr/local/supervisord.conf, supervisord.conf, etc/supervisord.conf, /etc/supervisord.conf, /etc/supervisor/supervisord.conf

we have to create one in order for it to work:

mkdir /etc/supervisord
echo_supervisord_conf > /etc/supervisord.conf

now we need to prepare service to start and enable:

wget https://gist.githubusercontent.com/mozillazg/6cbdcccbf46fe96a4edd/raw/2f5c6f5e88fc43e27b974f8a4c19088fc22b1bd5/supervisord.service -O /usr/lib/systemd/system/supervisord.service
systemctl daemon-reload
systemctl start supervisord
systemctl enable supervisord

to make sure everything is working you can run systemctl status supervisord

you need to change the configuration file that you just have created, vi /etc/supervisord/supervisord.conf and make sure [include] which is in the end of the file is uncommented and add the following line to it:

[include]
files = conf.d/*.conf

now default configuration is set and supervisor can look for your configuration files.

mkdir -p /etc/supervisord/conf.d

now create your supervisor configuration file in the directory we just created:

vi /etc/supervisord/conf.d/your_app_conf.conf

paste your configuration:

[program:pezhvak-ai-worker]
process_name=%(program_name)s_%(process_num)02d
directory=path/to/pezhvak.space
command=php artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=path/to/pezhvak.space/storage/logs/worker.log

** Note: directory should be set in full path, it does not recognize ~ as home direectory somehow **

and now you need to inform supervisor to reload configurations and start workers:

supervisorctl reread
supervisorctl update
supervisorctl start all

if anything goes wrong you can check the log files in the 'stdout_logfile' you specified.

to check status of your workers you can run supervisorctl status

All done, enjoy.

*** NOTE ***

everytime you update your laravel application, or .env file, you need to restart your workers for changes to take effect:

supervisorctl restart all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment