Supervisor
Supervisor is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems.
Installation
sudo apt install supervisor -yIn /etc/supervisor/supervisord.conf, check if this exist.
[include]
files = /etc/supervisor/conf.d/*.confAdd configuration
Create a new configuration file for your application.
sudo vim /etc/supervisor/conf.d/app-name-worker.confHere an example for a Laravel application with PHP 8.2.
- Replace
app-namewith the name of your application. - Replace
php8.2with the PHP version you are using. - Replace
/var/www/app-namewith the path to your application. - Replace
nginxwith the user that runs the application.
[program:app-name-worker]
process_name=%(program_name)s
command=php8.2 /var/www/app-name/artisan queue:work database --sleep=3 --tries=3
autostart=true
autorestart=true
user=nginx
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/app-name/storage/logs/worker.log
stopwaitsecs=3600When you create a new config, use these commands.
sudo supervisorctl reread
sudo supervisorctl updateUsage
Start the supervisor worker with this command.
supervisorctl start app-name-workerWhen you deploy a new app version, restart supervisor worker with this command.
supervisorctl restart app-name-workerRestart without sudo
To restart supervisor from CI, you have to allow restart without sudo.
sudo vim /etc/supervisor/supervisord.confReplace USER with your username, and nginx with the group that runs the application.
[unix_http_server]
chown=YOUR_USER:nginxRestart supervisor.
sudo service supervisor restartNow USER can restart supervisor without sudo.
List all workers
supervisorctlExample of output.
app-name-worker RUNNING pid 40598, uptime 0:03:30Global commands
If workers use command with local user, you have to add this user to the global commands. Here, the example is /home/$USER/.cargo/bin/scout-seeker, by default supervisor user, nginx, can't run this command.
Copy binary to /usr/local/bin.
sudo cp /home/$USER/.cargo/bin/scout-seeker /usr/local/binVerify that the binary is in the path for the supervisor user.
sudo -u nginx which scout-seekersudo su -l nginx -s /bin/bash
which scout-seeker