What is Supervisor and how to set it up
How to install Supervisor and manage long-running processes on a server.
Supervisor is a process manager that simplifies running and monitoring long-lived programs. It's particularly useful for keeping background processes alive on a VPS or dedicated server.
Supervisor has two components: supervisord — the server process that spawns and monitors child processes — and supervisorctl, a command-line and web interface for managing supervisord.
Installation
On Debian and Ubuntu, install Supervisor from the standard repository:
apt-get install supervisor
Configuration
The configuration file is located at /etc/supervisor/supervisord.conf on Debian and Ubuntu, or /etc/supervisord.conf on other distributions.
To add a process, define a program 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
Parameter descriptions:
[program:worker]— the process name.command— path to the executable.stdout_logfile— path to the log file for console output.autostart— start the process automatically when Supervisor starts.autorestart— restart the process automatically if it crashes.user— the user account the process runs under.stopsignal— the signal sent to stop the process.numprocs— the number of process instances to run.
After updating the configuration, restart Supervisor:
/etc/init.d/supervisor restart
Web interface
Supervisor includes a built-in web interface for monitoring and controlling processes. To enable it, uncomment and configure the [inet_http_server] section in the configuration file:
[inet_http_server]
port=127.0.0.1:9001
username=some_user_name
password=some_password
Event monitoring
Supervisor has a built-in event listener mechanism for receiving error notifications. Here's an example configuration that sends an alert when memory usage exceeds a threshold:
[eventlistener:memmon]
command=memmon -a 200MB -m error@site.com
events=TICK_60
Help
If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!