Tuesday, 9 May 2023

How to install Supervisor on Ubuntu

1. Install Supervisor  

sudo apt update
sudo apt install supervisor 
sudo systemctl status supervisor 
sudo systemctl start supervisor
sudo systemctl stop supervisor
sudo systemctl restart supervisor 

2. To add programs to Supervisor

- way 1:  configure it by editing the configuration file located at /etc/supervisor/supervisord.conf.

- way 2: create a new configuration file with a .conf extension in the /etc/supervisor/conf.d/ directory. 

* reload supervisor

sudo supervisorctl reread
sudo supervisorctl update 

3. example supervisor.conf for laravel

[supervisord]
nodaemon=true
loglevel = info
logfile=/var/log/supervisord.log
pidfile=/var/run/supervisord.pid

[group:laravel-worker]
priority=999
programs=nginx,php8-fpm,laravel-schedule,laravel-queue,chatgpt-python-handle-data

[program:nginx]
priority=10
autostart=true
autorestart=true
stderr_logfile_maxbytes=0
stdout_logfile_maxbytes=0
stdout_events_enabled=true
stderr_events_enabled=true
command=/usr/sbin/nginx -g 'daemon off;'
stderr_logfile=/var/log/nginx/error.log
stdout_logfile=/var/log/nginx/access.log

[program:php8-fpm]
priority=5
autostart=true
autorestart=true
stderr_logfile_maxbytes=0
stdout_logfile_maxbytes=0
command=/usr/local/sbin/php-fpm -R
stderr_logfile=/var/log/nginx/php-error.log
stdout_logfile=/var/log/nginx/php-access.log

[program:laravel-queue]
numprocs=5
autostart=true
autorestart=true
redirect_stderr=true
process_name=%(program_name)s_%(process_num)02d
stdout_logfile=/var/log/nginx/worker.log
command=php /var/www/artisan queue:work

[program:laravel-schedule]
numprocs=1
autostart=true
autorestart=true
redirect_stderr=true
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/artisan schedule:work
stdout_logfile=/var/log/nginx/schedule.log
 
[program:chatgpt-python-handle-data]
numprocs=1
autostart=true
autorestart=true
redirect_stderr=true
process_name=%(program_name)s_%(process_num)02d
command=/bin/bash -c 'cd /var/www/chatgpt-python/ && python3 /var/www/chatgpt-python/main.py'
stdout_logfile=/var/log/nginx/chatgpt-python.log 


Thank you

No comments:

Post a Comment

Golang Advanced Interview Q&A