How to Fix Supervisor Not Loading New Configuration Files for Django/Gunicorn Deployment


2 views

When trying to deploy a Django application using Gunicorn and Supervisor, you might encounter the frustrating error:

# supervisorctl start myapp_live
myapp_live: ERROR (no such process)

This typically happens when Supervisor isn't properly aware of your configuration file, even though everything appears correctly set up.

Your configuration file at /home/myapp/live/deploy/supervisord_live.ini looks correct:

[program:myapp_live]
command=/usr/local/bin/gunicorn_django --log-file /home/myapp/logs/gunicorn_live.log --log-level info --workers 2 -t 120 -b 127.0.0.1:10000 -p deploy/gunicorn_live.pid webapp/settings_live.py
directory=/home/myapp/live
environment=PYTHONPATH='/home/myapp/live/eco/lib'
user=myapp
autostart=true
autorestart=true

1. Supervisor Not Reading the Config File

Even with a symlink in /etc/supervisor/conf.d/, Supervisor might not be reading your config. Try these steps:

# Check if supervisor is running
sudo service supervisor status

# Reread configuration files
sudo supervisorctl reread

# Update configuration (forces reload)
sudo supervisorctl update

2. File Permissions and Ownership

Ensure the config file has proper permissions:

sudo chmod 644 /home/myapp/live/deploy/supervisord_live.ini
sudo chown root:root /etc/supervisor/conf.d/myapp-live.conf

3. Configuration File Format

Supervisor is particular about file formats. Your .ini file should work, but sometimes using .conf extension helps:

sudo mv /etc/supervisor/conf.d/myapp-live.conf /etc/supervisor/conf.d/myapp-live.ini
sudo supervisorctl update

Check Supervisor's main log for clues:

sudo tail -f /var/log/supervisor/supervisord.log

You can also check if your program is in the list of available programs:

sudo supervisorctl avail

Instead of using symlinks, you can directly include your config in /etc/supervisor/supervisord.conf:

[include]
files = /etc/supervisor/conf.d/*.conf /home/myapp/live/deploy/supervisord_live.ini

Then restart Supervisor:

sudo service supervisor restart

After making changes, verify everything works:

sudo supervisorctl status myapp_live
sudo supervisorctl start myapp_live
sudo supervisorctl tail -f myapp_live

When Supervisor fails to recognize new configuration files for Gunicorn/Django deployments, you'll typically see:

# supervisorctl status
myapp_live: ERROR (no such process)

# supervisorctl reload
No config updates to processes

First verify if Supervisor actually sees your config file:

# Check parsed configuration
sudo supervisorctl -c /etc/supervisor/supervisord.conf status

# Alternative method to see loaded configs
sudo supervisorctl -c /etc/supervisor/supervisord.conf avail

A common pitfall is symlinks in /etc/supervisor/conf.d/. While your setup shows a symlink:

lrwxrwxrwx 1 root root 48 Dec 4 18:02 myapp-live.conf -> /home/myapp/live/deploy/supervisord_live.ini

Try these diagnostic steps:

# Check symlink resolution
sudo ls -l /etc/supervisor/conf.d/myapp-live.conf

# Verify file permissions (Supervisor runs as root)
sudo -u root test -r /home/myapp/live/deploy/supervisord_live.ini && echo "Readable" || echo "Not readable"

Instead of symlinks, consider these approaches:

# Option 1: Direct config file
sudo cp /home/myapp/live/deploy/supervisord_live.ini /etc/supervisor/conf.d/myapp-live.conf

# Option 2: Change include pattern in supervisord.conf
[include]
files = /etc/supervisor/conf.d/*.conf /etc/supervisor/conf.d/*.ini

Add these parameters to your supervisord.conf for better debugging:

[supervisord]
logfile = /var/log/supervisor/supervisord.log
logfile_maxbytes = 50MB
logfile_backups=10
loglevel = debug

After any config changes, follow this sequence:

# Stop all managed processes
sudo supervisorctl stop all

# Reread config files
sudo supervisorctl reread

# Update process groups
sudo supervisorctl update

# Start your application
sudo supervisorctl start myapp_live

For Django/Gunicorn deployments, ensure your config includes:

[program:myapp_live]
command=/path/to/venv/bin/gunicorn webapp.wsgi:application \
    --bind 127.0.0.1:10000 \
    --workers 3 \
    --pid /tmp/gunicorn_live.pid \
    --timeout 120 \
    --pythonpath /home/myapp/live
directory=/home/myapp/live
user=myapp
autostart=true
autorestart=true
environment=PYTHONPATH="/home/myapp/live/eco/lib"

Check these post-startup indicators:

# Check supervisor's perspective
sudo supervisorctl status myapp_live

# Verify Gunicorn processes
ps aux | grep gunicorn

# Check port binding
sudo netstat -tulnp | grep 10000

# Examine application logs
tail -f /home/myapp/logs/gunicorn_live.log