liveBook · Manning

Supervisor

As explained in Road to Kubernetes

Supervisor is a process-control system for starting, stopping, and monitoring background processes on Unix-like operating systems.

Running Python and Node.js applications manually works during deployment, but production services should continue running without keyboard input. Supervisor manages these applications as background processes and can start, stop, or restart them when needed or when the system does. section 3.4.3 section 3.5

Supervisor uses one configuration file per application. Each file declares the process name, working directory, startup command, automatic-start and restart behavior, retry count, and standard-output log locations. section 3.5.2

A practical Supervisor setup follows this sequence:

  • Install Supervisor with the system package manager; installation creates /etc/supervisor/conf.d/ for application configurations. section 3.5.1
  • Create a configuration file that names the process and supplies its directory, command, restart policy, retries, and log paths. section 3.5.2
  • Check managed applications with supervisorctl status and control individual processes with start, stop, or restart. section 3.5.1

Managing two web applications

A Python application can run through Gunicorn on port 8888, while an Express application runs through Node.js on port 3000. Separate configurations set autostart=true, autorestart=true, and startretries=3 for each process, with separate stdout and stderr logs. After deployment, a Git post-receive hook can install updated dependencies and restart the corresponding Supervisor process.

Listing 3.27 Supervisor configuration for Python
export APP_CMD="/opt/venv/bin/gunicorn \
    --worker-class uvicorn.workers.UvicornWorker \
    main:app --bind "0.0.0.0:8888" \
    --pid /var/run/roadtok8s-py.pid"
cat << EOF > /etc/supervisor/conf.d/roadtok8s-py.conf
[program:roadtok8s-py]
directory=/opt/projects/roadtok8s/py/src
command=$APP_CMD
autostart=true
autorestart=true
startretries=3
stderr_logfile=/var/log/supervisor/roadtok8s/py/stderr.log
stdout_logfile=/var/log/supervisor/roadtok8s/py/stdout.log
EOF

Inspect a complete Supervisor configuration, including the application command, restart policy, and logging paths. section 3.5.2

How Road to Kubernetes covers it

How deep it goes
Explains installation, declarative configuration, logging, lifecycle commands, status checks, and deployment-hook restarts.
Examples
Uses Gunicorn Python and Express Node.js configurations, log directories, status output, and Git post-receive restart hooks.
What it assumes
Assumes command-line access, installed application runtimes, and manually runnable applications; teaches Supervisor setup from installation onward.
What you can do after
Operate/configure Python and Node.js services with automatic startup, restart policies, logging, status checks, and deployment-triggered restarts.
How it connects
Connects process supervision with Python, Node.js, Gunicorn, NGINX, Git hooks, and continuous deployment.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Road to Kubernetes. The section links point to the parts of the book it draws on.