Using Supervisor to Manage and Auto‑Restart Python Scripts on Linux
This tutorial explains how to install Supervisor on CentOS and Ubuntu, configure its main and program-specific files, and use it to monitor a continuously running Python script, automatically restarting the script if it crashes or is killed.
Supervisor is a Python‑based client/server daemon for Unix‑like systems that monitors and automatically restarts managed processes.
The article first explains why simple nohup cannot monitor or restart scripts, then introduces Supervisor, its compatibility with Python 2.7/3.4+, and its installation methods on CentOS (yum) and Ubuntu (apt), as well as Python package installation via pip or easy_install.
It describes the required configuration files: supervisord.conf for the daemon and separate .ini files for each managed program, showing typical locations (/etc/, /etc/supervisord.d) and how to generate a default config with echo_supervisord_conf >> supervisord.conf .
A practical example creates a simple hello.py script that repeatedly prints “hello world”, places it under /home/yz/supervisor_study/ , and configures both the daemon and a program section ( hello.ini ) to log output to a project‑specific logs directory.
After starting Supervisor with supervisord and controlling the program via supervisorctl , the article shows that killing the Python process results in Supervisor automatically restarting it, confirming the auto‑restart feature.
Finally, common Supervisor commands for starting, stopping, and reloading configurations are listed, and a link to the official documentation is provided.
360 Tech Engineering
Official tech channel of 360, building the most professional technology aggregation platform for the brand.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.