Managing applications and services on Linux can feel overwhelming, especially when you need to ensure they keep running reliably. Enter Supervisor Linux – a powerful process management tool that simplifies how you monitor, control, and restart your applications automatically.
Whether you’re running web servers, background scripts, or API services, understanding how to use Supervisor Linux effectively will save you countless hours of manual intervention. This comprehensive guide walks you through everything from basic installation to advanced configuration techniques.
By the end of this article, you’ll have the confidence to deploy and manage production applications using Supervisor’s robust process monitoring capabilities.
What Is Supervisor in Linux?
A Brief Overview of Process Monitoring
Supervisor Linux is a client-server system that monitors and controls processes on Unix-like operating systems. Unlike traditional init systems, Supervisor focuses specifically on managing user-level applications and services that need constant oversight.
The system consists of three main components:
- supervisord: The server daemon that manages child processes
- supervisorctl: The command-line client for controlling supervisord
- Web interface: An optional browser-based management tool
Supervisor excels at keeping applications running continuously, automatically restarting them when they crash or exit unexpectedly. This makes it invaluable for production environments where uptime is critical.
Why Use Supervisor Instead of Other Tools?
Supervisor Linux offers several advantages over alternative process managers:
Simplicity and Ease of Use: Configuration files use straightforward INI format that’s human-readable and easy to modify. You don’t need to learn complex syntax or scripting languages.
Reliable Process Monitoring: Supervisor actively monitors child processes and can detect when they terminate, hang, or consume excessive resources.
Centralized Management: All your applications live under one umbrella, making it simple to start, stop, and monitor multiple services from a single interface.
Rich Logging Capabilities: Built-in log rotation and management ensure you can debug issues without overwhelming your disk space.
Cross-Platform Compatibility: While we focus on Linux, Supervisor works across Unix-like systems including macOS and FreeBSD.
How Supervisor Works Behind the Scenes
The Supervisor Daemon Explained
The supervisord daemon serves as the heart of the Supervisor Linux system. When you start supervisord, it reads configuration files and spawns child processes according to your specifications.
Here’s what happens during the startup process:
- Configuration Loading: supervisord reads the main configuration file and any program-specific configs
- Process Spawning: Child processes start according to their autostart settings
- Monitoring Loop: The daemon continuously checks process status and resource usage
- Event Handling: When processes exit or crash, supervisord takes appropriate action based on your configuration
The daemon runs as a long-lived process, typically started at boot time. It maintains process state information and provides APIs for external clients to interact with managed applications.
Supervisorctl: Your Command Line Companion
Supervisorctl acts as your primary interface for managing Supervisor Linux processes. This command-line tool connects to the supervisord daemon and allows you to:
- View process status and resource usage
- Start, stop, and restart individual applications
- Read real-time log output
- Reload configuration changes without stopping the daemon
The interactive shell mode provides tab completion and command history, making it user-friendly for both beginners and experienced administrators.
Installing Supervisor on Popular Linux Distributions
How to Install Supervisor on Ubuntu and Debian
Installing Supervisor Linux on Debian-based systems is straightforward using the package manager:
# Update package repositories
sudo apt update
# Install Supervisor
sudo apt install supervisor
# Start and enable the service
sudo systemctl start supervisor
sudo systemctl enable supervisor
For newer versions of Ubuntu (20.04+), you can also install via snap:
sudo snap install supervisor
The default installation creates configuration directories at /etc/supervisor/
and sets up log files in /var/log/supervisor/
.
Installing Supervisor on CentOS and Red Hat Systems
Supervisor Linux installation on RHEL-based distributions requires the EPEL repository:
# Install EPEL repository (CentOS 7/8)
sudo yum install epel-release
# For CentOS Stream 9 or RHEL 9
sudo dnf install epel-release
# Install Supervisor
sudo yum install supervisor
# or for newer systems
sudo dnf install supervisor
# Start and enable the service
sudo systemctl start supervisord
sudo systemctl enable supervisord
Note that the service name is supervisord
on RHEL systems, not supervisor
as on Debian systems.
Verifying Installation and Version
Confirm your Supervisor Linux installation works correctly:
# Check Supervisor version
supervisord --version
# Verify the service is running
sudo systemctl status supervisor
# or for RHEL systems
sudo systemctl status supervisord
# Test the command-line client
supervisorctl version
You should see version information and confirmation that the daemon is active and running.
Getting Started with Supervisor Configuration
Understanding the Supervisor Configuration File Structure
Supervisor Linux uses INI-style configuration files that are easy to read and modify. The main configuration file is typically located at /etc/supervisor/supervisord.conf
.
Here’s the basic structure:
[unix_http_server]
file=/var/run/supervisor.sock
chmod=0700
[supervisord]
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
childlogdir=/var/log/supervisor
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock
[include]
files = /etc/supervisor/conf.d/*.conf
The [include]
section tells Supervisor Linux to load additional configuration files from the conf.d
directory, keeping your setup organized.
Creating and Managing Supervisor Program Files
Program configurations define how Supervisor Linux should manage your applications. Create individual .conf
files in /etc/supervisor/conf.d/
for each application:
[program:my-web-app]
command=/usr/bin/python3 /path/to/your/app.py
directory=/path/to/your/project
user=www-data
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/supervisor/my-web-app.log
This configuration tells Supervisor to:
- Run the Python application as the
www-data
user - Start the program automatically when supervisord starts
- Restart the program if it crashes
- Combine stderr with stdout for logging
- Write logs to a specific file
Key Parameters You Should Know
Essential Supervisor Linux configuration parameters include:
Process Control Parameters:
command
: The actual command to executedirectory
: Working directory for the processuser
: System user to run the process asenvironment
: Environment variables to set
Startup Behavior:
autostart
: Whether to start the program when supervisord startsautorestart
: When to restart the program (true, false, or unexpected)startsecs
: Minimum runtime before considering the start successful
Logging Configuration:
stdout_logfile
: Where to write standard outputstderr_logfile
: Where to write error outputredirect_stderr
: Combine stderr with stdout
Running and Managing Programs with Supervisor
Starting, Stopping, and Restarting Services
Supervisor Linux provides intuitive commands for process management through supervisorctl:
# Start a specific program
supervisorctl start my-web-app
# Stop a program
supervisorctl stop my-web-app
# Restart a program
supervisorctl restart my-web-app
# Start all programs
supervisorctl start all
# Check status of all programs
supervisorctl status
The status command shows each program’s state (RUNNING, STOPPED, FATAL, etc.) along with uptime and process ID information.
Automatically Restarting Crashed Applications
One of Supervisor Linux’s most valuable features is automatic restart capability. Configure the autorestart
parameter to control restart behavior:
[program:critical-service]
command=/usr/bin/node /app/server.js
autorestart=true # Always restart
startsecs=10 # Must run 10 seconds to be considered started
startretries=3 # Try to start 3 times before giving up
Autorestart Options:
true
: Always restart the programfalse
: Never restart automaticallyunexpected
: Only restart if the program exits with an unexpected exit code
Managing Services with Supervisorctl
The supervisorctl interactive shell provides powerful management capabilities:
# Enter interactive mode
supervisorctl
# Inside the shell:
supervisor> status
supervisor> restart all
supervisor> tail my-web-app
supervisor> reload
supervisor> quit
Interactive mode supports tab completion and command history, making it efficient for managing multiple services.
Setting Up Supervisor to Start on Boot
Enabling Supervisor as a System Service
Ensure Supervisor Linux starts automatically when your system boots:
# For systemd-based systems (Ubuntu 16.04+, CentOS 7+)
sudo systemctl enable supervisor
# Verify the service is enabled
sudo systemctl is-enabled supervisor
The systemd service file typically lives at /lib/systemd/system/supervisor.service
and handles the daemon lifecycle automatically.
Ensuring Applications Start Automatically on Reboot
Configure your applications to start with Supervisor Linux by setting autostart=true
in their configuration files:
[program:production-api]
command=/usr/bin/python3 /app/api.py
autostart=true
autorestart=true
user=api-user
After making configuration changes, reload Supervisor:
# Reload configuration and restart affected programs
supervisorctl reread
supervisorctl update
# Or restart the entire supervisor service
sudo systemctl restart supervisor
Logging and Monitoring Applications with Supervisor
Accessing Real-Time Logs with Supervisor
Supervisor Linux provides excellent logging capabilities for monitoring your applications:
# View the last few lines of logs
supervisorctl tail my-web-app
# Follow logs in real-time
supervisorctl tail -f my-web-app
# View specific number of lines
supervisorctl tail -1000 my-web-app
You can also access logs directly from the filesystem at the paths specified in your configuration files.
Rotating Logs and Setting Limits
Prevent log files from consuming excessive disk space by configuring rotation:
[program:my-app]
command=/usr/bin/python3 app.py
stdout_logfile=/var/log/supervisor/my-app.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=10
This configuration limits each log file to 50MB and keeps 10 backup files, automatically rotating when limits are reached.
Debugging Services Using Log Output
Supervisor Linux makes debugging straightforward by centralizing log access:
# Check why a program failed to start
supervisorctl status my-app
supervisorctl tail my-app stderr
# View supervisord's own logs
sudo tail -f /var/log/supervisor/supervisord.log
Common issues like permission problems, missing dependencies, or configuration errors typically appear in the logs with helpful error messages.
Common Use Cases for Supervisor in Development and Production
Running Node.js and Python Apps with Supervisor
Supervisor Linux excels at managing web applications and services:
Node.js Application Example:
[program:node-api]
command=/usr/bin/node server.js
directory=/home/user/my-node-app
user=node-user
environment=NODE_ENV=production,PORT=3000
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/node-api.log
Python Flask Application:
[program:flask-app]
command=/usr/bin/python3 -m flask run --host=0.0.0.0 --port=5000
directory=/home/user/flask-project
user=flask-user
environment=FLASK_ENV=production
autostart=true
autorestart=true
Using Supervisor for Background Job Management
Supervisor Linux works perfectly for managing background workers and job processors:
[program:celery-worker]
command=/usr/bin/celery -A myapp worker --loglevel=info
directory=/home/user/django-project
user=celery-user
numprocs=4
process_name=%(program_name)s_%(process_num)02d
autostart=true
autorestart=true
This configuration starts four Celery worker processes, automatically numbering them for easy identification.
Keeping WebSocket and API Services Alive
Real-time applications benefit from Supervisor’s reliable monitoring:
[program:websocket-server]
command=/usr/bin/python3 websocket_server.py
directory=/app
user=websocket-user
autostart=true
autorestart=true
startsecs=5
startretries=3
stdout_logfile=/var/log/supervisor/websocket.log
Troubleshooting Supervisor Issues Like a Pro
Fixing “No Such File” and Config Errors
Common Supervisor Linux errors and their solutions:
"No such file or directory" errors:
# Check if the command path is correct
which python3
which node
# Verify the working directory exists
ls -la /path/to/your/project
# Ensure the script file has execute permissions
chmod +x /path/to/your/script.py
Configuration syntax errors:
# Test configuration validity
supervisord -t
# Check for specific program configuration issues
supervisorctl avail
Handling Permission Issues and Path Problems
Permission-related issues are common when configuring Supervisor Linux:
# Ensure the user can access the working directory
sudo -u your-app-user ls /path/to/project
# Check log file permissions
sudo chown your-app-user:your-app-user /var/log/supervisor/your-app.log
# Verify socket file permissions
ls -la /var/run/supervisor.sock
PATH environment issues:
[program:my-app]
command=/full/path/to/python3 app.py
environment=PATH="/usr/local/bin:/usr/bin:/bin"
How to Reload Configurations Safely
When you modify Supervisor Linux configurations, reload them properly:
# Safe reload process
supervisorctl reread # Read new configurations
supervisorctl update # Apply changes
supervisorctl status # Verify everything is working
# If programs don't start, check the logs
supervisorctl tail program-name
For major configuration changes, you might need to restart supervisord entirely:
sudo systemctl restart supervisor
Advanced Tips and Best Practices
Grouping Multiple Programs
Supervisor Linux supports program groups for managing related services:
[group:web-services]
programs=nginx-proxy,api-server,websocket-server
priority=999
[program:nginx-proxy]
command=/usr/sbin/nginx -g "daemon off;"
[program:api-server]
command=/usr/bin/python3 api.py
[program:websocket-server]
command=/usr/bin/node websocket.js
Manage the entire group with single commands:
supervisorctl start web-services:*
supervisorctl stop web-services:*
supervisorctl restart web-services:*
Securing Your Supervisor Setup
Implement security best practices for Supervisor Linux:
Restrict socket permissions:
[unix_http_server]
file=/var/run/supervisor.sock
chmod=0700
chown=root:root
Use dedicated users for applications:
# Create application-specific users
sudo useradd --system --no-create-home api-user
sudo useradd --system --no-create-home worker-user
Enable authentication for web interface:
[inet_http_server]
port=127.0.0.1:9001
username=admin
password=secure_password_here
Using Environment Variables Efficiently
Supervisor Linux supports flexible environment variable management:
[program:django-app]
command=/usr/bin/python3 manage.py runserver
environment=
DJANGO_SETTINGS_MODULE=myproject.settings.production,
DATABASE_URL=postgresql://user:pass@localhost/db,
SECRET_KEY=your-secret-key-here
For multiple environments, use separate configuration files:
production.conf
staging.conf
development.conf
Supervisor vs Other Process Managers
Supervisor vs Systemd: Which Should You Use?
Supervisor Linux and systemd serve different purposes, though they overlap in some areas:
Choose Supervisor when:
- Managing user-level applications and services
- You need detailed process monitoring and logging
- Working with development environments
- Managing multiple instances of the same application
Choose Systemd when:
- Managing system-level services
- You need tight integration with the Linux boot process
- Working with containerized environments
- Security and isolation are primary concerns
Many production setups use both: systemd manages supervisord as a system service, while Supervisor Linux handles application processes.
Comparing Supervisor with PM2 and Forever
PM2 (primarily for Node.js):
- Better for Node.js applications specifically
- Built-in cluster mode and load balancing
- More complex configuration and learning curve
Forever (Node.js only):
- Simpler than PM2 but less feature-rich
- Limited to Node.js applications
- Minimal configuration options
Supervisor Linux advantages:
- Language-agnostic (works with any executable)
- Mature, stable, and well-documented
- Excellent logging and monitoring capabilities
- Simple configuration format
Choosing the Right Tool for Your Workflow
Consider these factors when selecting a process manager:
Application Type: Supervisor Linux works with any programming language, while PM2 and Forever focus on Node.js.
Complexity Requirements: Supervisor offers a good balance between features and simplicity.
Team Expertise: Supervisor’s straightforward configuration makes it accessible to developers and system administrators alike.
Production Needs: For mission-critical applications, Supervisor’s reliability and monitoring capabilities provide peace of mind.
Conclusion
Key Takeaways for New Users
Supervisor Linux provides a robust, user-friendly solution for process management and monitoring. The key benefits include:
- Reliability: Automatic restart capabilities keep your applications running
- Simplicity: INI-style configuration files are easy to understand and modify
- Monitoring: Built-in logging and status reporting simplify troubleshooting
- Flexibility: Works with applications written in any programming language
Start with basic configurations and gradually explore advanced features as your needs grow. The investment in learning Supervisor Linux pays dividends in reduced downtime and easier application management.
Where to Go Next with Supervisor Linux
Continue your Supervisor Linux journey by exploring:
- Official Documentation: Visit the Supervisor documentation for comprehensive reference materials
- Community Resources: Join forums and discussion groups to learn from experienced users
- Integration Patterns: Explore how Supervisor integrates with Docker, configuration management tools, and monitoring systems
- Advanced Features: Experiment with event listeners, XML-RPC interfaces, and custom plugins
Remember that mastering Supervisor Linux is an iterative process. Start with simple use cases, build confidence through hands-on practice, and gradually tackle more complex scenarios as your expertise grows.