How to Turn Any Linux Process into a Managed Daemon with Supervisor
This guide explains how Supervisor, a Python‑based process manager, can convert ordinary command‑line programs into monitored daemons on Linux, compares it with nohup, setsid and screen, and provides step‑by‑step installation, configuration, and web‑interface setup instructions.
Overview
Supervisor is a Python‑written, general‑purpose process management tool that turns a normal command‑line process into a background daemon, monitors its status, and automatically restarts it on failure.
It launches managed processes as child processes of the supervisor daemon using a fork/exec model, so you only need to specify the executable path in the supervisor configuration file.
The tool can also capture detailed exit information, optionally trigger alerts, and run each managed process under a non‑root user.
Typical Scenarios
Running a program in the background on Linux.
Keeping a program alive after the terminal is closed.
Running a program as a daemon over an SSH session.
Advantages Compared to Other Tools
nohup : only detaches a command; lacks automatic restart and status monitoring, whereas Supervisor provides both and a convenient supervisorctl interface.
setsid : creates a new session but does not offer centralized management; Supervisor can start, stop, and monitor multiple processes together.
screen : provides a virtual terminal for interactive sessions; Supervisor focuses on automated process control, logging, and restart capabilities.
Installation (Ubuntu 20.04 Example)
Step 1 – Update Package Index
apt-get update -yStep 2 – Install Supervisor
Supervisor is available in the default Ubuntu repositories. apt-get install supervisor -y Verify the installed version: supervisord -v Check the service status:
sudo systemctl status supervisorStep 3 – Enable the Web Interface
Edit /etc/supervisor/supervisord.conf and add:
[inet_http_server]
port=*:9001
username=admin
password=adminRestart the service to apply the changes:
systemctl restart supervisorStep 4 – Manage a Redis Queue Process
Create a program configuration file, e.g., /etc/supervisor/conf.d/think-redis-queue.conf:
[program:think-redis-queue]
command=/usr/local/php-8.3.7/bin/php /home/www/website/train.tinywan.com/think redis-queue consumer
autostart=true
autorestart=true
startretries=5
numprocs=1
startsecs=0
process_name=%(program_name)s_%(process_num)02d
stderr_logfile=/var/log/supervisor/%(program_name)s_stderr.log
stderr_logfile_maxbytes=10MB
stdout_logfile=/var/log/supervisor/%(program_name)s_stdout.log
stdout_logfile_maxbytes=10MBReload the configuration and start the program:
sudo supervisorctl reread
sudo supervisorctl updateCheck that the process is running:
sudo supervisorctl status think-redis-queue:think-redis-queue_00Stop or start the process with:
supervisor> stop think-redis-queue:think-redis-queue_00
supervisor> start think-redis-queue:think-redis-queue_00Step 5 – Access the Web Interface
Nginx configuration for proxying the Supervisor web UI: <code>server { listen 443 ssl http2; server_name supervisor.tinywan.cn; ssl_certificate /home/www/.acme.sh/supervisor.tinywan.cn/supervisor.tinywan.cn.cer; ssl_certificate_key /home/www/.acme.sh/supervisor.tinywan.cn/supervisor.tinywan.cn.key; location / { proxy_pass http://0.0.0.0:9001; proxy_buffering off; } }</code>
Common Supervisor Commands
supervisorctl status // view status of all processes
supervisorctl stop es // stop a specific process
supervisorctl start es // start a specific process
supervisorctl restart es // restart a specific process
supervisorctl update // reload changed configuration files
supervisorctl reload // restart all programs with new configCentOS Installation
Install
yum install supervisorConfiguration File
/etc/supervisord.confInclude Directory
[include]
files = supervisord.d/*.iniExample Program Config (redis-queue-order-consumer.ini)
[program:redis-queue-order-consumer]
command=/usr/local/php-8.4/bin/php /home/wwwroot/order.tinywan.com/think redis-queue order-consumer
user=www
autostart=true
autorestart=true
startretries=5
numprocs=1
startsecs=0
process_name=%(program_name)s_%(process_num)02d
stderr_logfile=/var/log/supervisor/%(program_name)s_stderr.log
stderr_logfile_maxbytes=10MB
stdout_logfile=/var/log/supervisor/%(program_name)s_stdout.log
stdout_logfile_maxbytes=10MBSupervisorctl Command
supervisorctlView Service Status
supervisor> status
redis-queue-live-consumer:redis-queue-order-consumer_00 RUNNING pid 1692927, uptime 0:16:17Stop a specific service: stop all Start all services:
start allSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
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.
