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
