Supervisord is a powerful process control system, but unlike many Linux services, it doesn't include built-in startup scripts for modern init systems. This becomes particularly problematic when you need reliable process management across server reboots.
For Ubuntu 16.04 and later (which use systemd), we can create a proper service unit file. This is more reliable than legacy init.d scripts and integrates better with modern Linux systems.
[Unit]
Description=Supervisor process control system
Documentation=http://supervisord.org
After=network.target
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
1. Create the service file:
sudo nano /etc/systemd/system/supervisord.service
2. Paste the configuration above and save
3. Enable and start the service:
sudo systemctl enable supervisord
sudo systemctl start supervisord
Check the service status with:
systemctl status supervisord
You should see output indicating active (running) status. For debugging, use:
journalctl -u supervisord -f
For Ubuntu 14.04 or earlier, use this Upstart config in /etc/init/supervisord.conf:
description "Supervisor daemon"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
Permission problems: Ensure the user running supervisord has proper access to:
- /var/log/supervisor/
- /var/run/supervisor.sock
- Your application's working directory
Configuration errors: Always test your config with:
supervisord -c /etc/supervisor/supervisord.conf
When installing Supervisord via pip (pip install supervisor
), you'll notice it doesn't provide systemd or init scripts out of the box. This becomes problematic when you need reliable process supervision that persists across reboots. While some user-contributed init scripts exist, they often fail due to path issues or incorrect service definitions.
The most robust solution is creating a proper systemd service file. Here's how to implement it:
# /etc/systemd/system/supervisord.service
[Unit]
Description=Supervisor process control system
Documentation=http://supervisord.org
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/local/bin/supervisorctl shutdown
ExecReload=/usr/local/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=50s
[Install]
WantedBy=multi-user.target
After creating the service file:
sudo systemctl daemon-reload
sudo systemctl enable supervisord
sudo systemctl start supervisord
Check service status with:
systemctl status supervisord
Expected output should show "active (running)". For debugging, use journalctl:
journalctl -u supervisord -f
For those using configuration management tools, here's an Ansible snippet:
- name: Ensure supervisor systemd service
template:
src: supervisord.service.j2
dest: /etc/systemd/system/supervisord.service
mode: 0644
notify:
- reload systemd
- restart supervisor
If you encounter "command not found" errors, ensure Python paths are correctly set in the service file. For virtualenv installations, modify the Exec paths accordingly:
ExecStart=/path/to/venv/bin/supervisord -c /etc/supervisor/supervisord.conf