Supervisor, the process manager for UNIX systems
Supervisor is a client/server system used in UNIX systems to control operating system processes. One of the most important advantages of supervisor is that it allows a service to be automatically restarted after it has crashed. Supervisor also allows configuring a number of retry attempts before considering the service down, it also allows defining the initialization priority of the processes among other things that make process management easier.
Key Features of Supervisor
1. Process Monitoring: Supervisor continuously monitors the status of managed processes, tracking their health and resource utilization.
2. Automatic Restarts: If a managed process crashes or exits unexpectedly, Supervisor can automatically restart it, ensuring high availability.
3. Process Grouping: Supervisor allows processes to be grouped, enabling convenient control and monitoring of related processes as a single unit.
4. Logging and Notifications: It provides comprehensive logging capabilities to record process events, and can send notifications based on predefined rules.
Configuration Management: Supervisor's configuration files allow easy management of processes, including specifying startup commands, environment variables, and resource limits.
Applications
One of the interesting things that you can manage with supervisor is Managing Web Server Processes.
Suppose you have a web application consisting of multiple server components. With Supervisor, you can ensure that all the necessary processes are running and restart them if they crash.
Here's an example configuration file for Supervisor, named webserver.conf
:
[program:webapp]
command=/usr/bin/python3 /path/to/webapp.py
directory=/path/to/webapp
user=webapp_user
autostart=true
autorestart=true
redirect_stderr=true
In this example, Supervisor manages a Python-based web application. It specifies the startup command, the working directory, the user under which the process should run, and enables automatic restarts if the process crashes.
Other interesting application is Managing Worker Processes. Suppose you have a background task processing system that relies on multiple worker processes. You can use Supervisor to ensure the workers are always running and recover from failures.
Consider the following configuration file, named worker.conf
:
[program:worker1]
command=/usr/bin/python3 /path/to/worker.py
process_name=%(program_name)s_%(process_num)02d
numprocs=4
numprocs_start=1
autostart=true
autorestart=true
redirect_stderr=true
In this example, Supervisor manages four worker processes. It uses the numprocs and numprocs_start directives to specify the number and starting index of the processes. The process_name directive allows each worker to have a unique identifier.
Check out our installation guides by clicking the following links.
- Supervisor Installation on MacOS
- Supervisor Installation on Debian