What is Supervisor?
Running processes in supervisor
Using Supervisor is convenient when working with continuously running processes on a VPS or a dedicated server. It helps automate the startup and control of services, ensuring stable project operation.
Supervisor is a process manager that simplifies the management of long-running applications and provides an easy-to-use interface. It consists of a server component called supervisord, which creates and manages processes, and an interface called supervisorctl (command-line or web), used to control and monitor supervisord.
Installation
On Debian/Ubuntu, Supervisor can be installed from the repository:
apt-get install supervisor
After installation, Supervisor needs to be configured, and the programs or processes it will manage must be added. The configuration file is located at /etc/supervisor/supervisord.conf (for Ubuntu and Debian) or /etc/supervisord.conf on other systems.
To add a new process (worker), include the following section in the configuration file:
[program:worker]
command=/usr/bin/php /var/www/worker.php
stdout_logfile=/var/log/worker.log
autostart=true
autorestart=true
user=www-data
stopsignal=KILL
numprocs=1
Parameters:
[program:worker]
— the name of the process to which all following parameters apply;command=/usr/bin/php /var/www/worker.php
— path to the executable file;stdout_logfile=/var/log/worker.log
— log file for console output;autostart=true
— automatically start the process when Supervisor starts;autorestart=true
— automatically restart the process if it crashes;user=www-data
— the user under which the process runs;stopsignal=KILL
— the signal used to stop the process;numprocs=1
— the number of process instances to run.
After adding new processes, Supervisor must be restarted:
/etc/init.d/supervisor restart
Supervisor also provides a web interface through supervisorctl, which can be enabled in the configuration file. To do this, modify the [inet_http_server] section and specify the correct username and password:
[inet_http_server]
port=127.0.0.1:9001
;username=some_user_name
;password=some_password
Additional features
Supervisor includes a built-in event monitoring system that can send notifications about errors:
[eventlistener:memmon]
command=memmon -a 200MB -m error@site.com
events=TICK_60