Operations 16 min read

Using Supervisor for Process Monitoring and Management on Unix-like Systems

This article introduces Supervisor, a client‑server process monitoring tool for Unix-like systems, explains why it solves persistent process deployment issues, walks through installation, configuration, command‑line usage, advanced features such as process groups and auto‑restart policies, and provides code examples for practical implementation.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Using Supervisor for Process Monitoring and Management on Unix-like Systems

Supervisor is a client/server process monitoring and management tool for Unix-like operating systems, designed to improve the stability of long‑running background services such as API servers or consumer processes.

Problem scenario : Deploying persistent processes with nohup cmd & can lead to unexpected termination, causing service interruptions.

Supervisor addresses this by automatically restarting failed processes and supporting grouped management.

Installation

<code>pip install supervisor</code>

Note: Supervisor does not support Windows.

Configuration

Generate a base configuration file:

<code>echo_supervisord_conf > /etc/supervisord.conf</code>

Key sections include [unix_http_server] , [supervisord] , [supervisorctl] , and optional [include] to load additional program files.

Create a directory for individual program configs and enable inclusion:

<code>mkdir /etc/supervisord.d
[include]
files = /etc/supervisord.d/*.ini
</code>

Example program configuration for a Python script test.py :

<code>[program:test]
command=python -u ./test.py
directory=/root/test/
redirect_stderr=true
stdout_logfile=/root/test/test.log
</code>

Link the program file into the include directory:

<code>ln ./supervisor-test.ini /etc/supervisord.d/supervisor-test.ini</code>

Running Supervisor

Start the daemon:

<code>supervisord</code>

Control processes with supervisorctl (e.g., status , start , stop , restart , signal ).

Advanced Features

Process groups allow batch operations:

<code>[group:test]
programs=test-task_service, test-collector
</code>

Use commands like stop test: to affect all members of the group.

Program options such as command , directory , numprocs , autostart , stdout_logfile , and redirect_stderr provide fine‑grained control.

Auto‑restart policy is governed by autorestart (values: true , false , unexpected ) and exitcodes . Experiments show that processes exiting with unexpected codes or being killed are automatically restarted, while normal exits are not.

Start‑up verification uses startsecs to determine if a process has started successfully; failures within this window trigger back‑off and eventual FATAL status.

Web interface can be enabled via [inet_http_server] for visual management, but should be secured.

Conclusion

Supervisor offers a robust solution for managing persistent services, supporting configuration inheritance, process grouping, signal handling, and customizable restart behavior, making it a valuable tool for system administrators and DevOps engineers.

AutomationlinuxSystem AdministrationSupervisorProcess Monitoring
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.