By giuliacta
Hi everyone! I’m on my first Django deployment on Digital Ocean and I can’t seem to get past an error that’s rising when I check the status of supervisor.
here’s my happ.conf file (/etc/supervisor/conf.d.happ.conf)
[program:happ]
command=sh /home/happ/gunicorn_start
user=happ
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/happ/logs/gunicorn.log
and here’s my gunicorn_start file (/home/happ/gunicorn_start)
#!/bin/bash
NAME="happ"
DIR=/home/happ/happ
USER=happ
GROUP=happ
WORKERS=3
BIND=unix:/home/happ/run/gunicorn.sock
DJANGO_SETTINGS_MODULE=happ.settings
DJANGO_WSGI_MODULE=happ.wsgi
LOG_LEVEL=error
cd $DIR
source ../venv/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DIR:$PYTHONPATH
exec ../venv/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $WORKERS \
--user=$USER \
--group=$GROUP \
--bind=$BIND \
--log-level=$LOG_LEVEL \
--log-file=-
Firstly I make the file executable:
chmod u+x gunicorn_start
Then I run the following commands:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl status happ
And once I run the status command I get the following error:
Exited too quickly.
Here’s what the log file says:
/home/happ/gunicorn_start: 2: /home/happ/gunicorn_start: : not found /home/happ/gunicorn_start: 12: /home/happ/gunicorn_start: : not found /home/happ/gunicorn_start: 13: cd: can’t cd to /home/happ/happ /home/happ/gunicorn_start: 14: /home/happ/gunicorn_start: source: not found /home/happ/gunicorn_start: 15: /home/happ/gunicorn_start: : not found /home/happ/gunicorn_start: 18: /home/happ/gunicorn_start: : not found /home/happ/gunicorn_start: 19: exec: …/venv/bin/gunicorn: not found Please note that the above commands are run inside the console not by the user root but by a user I created which is added to the sudoers list.
If anyone has any hint, please feel free to help out as I’ve been stuck on this issue for two days and I don’t really know where else to look for a solution. Thank you very much.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
I bet you are following the “simple is better than complex” “tutorial”. Actually people have been stuck with that issue for years. Nobody knows how to solve it and has made thousands of people quit the attempt to launch the app as it should with gunicorn and supervisor. There are countless of “tutorials” doing as if they were tutorials by presenting “how to properly configure and set up a full fledged django app in a production server”, but, why would they want to tell you how to do it? you would become a competitor and snatch jobs from them, so what they do is deliberately leave bugs that you will never be able to solve, so you can’t launch the application. They write tutorials to make a name for themselves, but not to teach you.
The error indicates several issues with your setup, particularly with paths, permissions, and the environment configuration. Let’s address each one step-by-step:
The line:
#!/bin/bash
should ensure the script uses the Bash shell. However, if the system cannot recognize the shebang, it may default to another shell (e.g., sh). Ensure the script begins with:
#!/bin/bash
and the file encoding is correct. Use dos2unix to fix any Windows-style line endings:
sudo apt install dos2unix
dos2unix /home/happ/gunicorn_start
The error cd: can’t cd to /home/happ/happ suggests the directory doesn’t exist or the script lacks permissions. Verify the directory exists and has the correct permissions:
ls -ld /home/happ/happ
Ensure the directory is accessible to the happ user:
sudo chown -R happ:happ /home/happ/happ
chmod -R 750 /home/happ/happ
The error source: not found may occur because the sh shell (used by default) does not recognize source. Replace source with ., which is POSIX-compliant:
. ../venv/bin/activate
The error exec: ../venv/bin/gunicorn: not found suggests the script cannot locate Gunicorn. Verify that Gunicorn is installed in your virtual environment:
/home/happ/venv/bin/pip show gunicorn
If it’s not installed, add it:
/home/happ/venv/bin/pip install gunicorn
Also, confirm the correct path to Gunicorn. Use the absolute path to Gunicorn in your gunicorn_start file:
exec /home/happ/venv/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $WORKERS \
--user=$USER \
--group=$GROUP \
--bind=$BIND \
--log-level=$LOG_LEVEL \
--log-file=-
Your Supervisor configuration may not properly recognize your script. Ensure gunicorn_start is executable:
chmod +x /home/happ/gunicorn_start
Then, update Supervisor:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl restart happ
Ensure the happ user can write to the logs directory:
sudo mkdir -p /home/happ/logs
sudo chown happ:happ /home/happ/logs
chmod 750 /home/happ/logs
If the script still fails, try running it manually as the happ user to see detailed errors:
sudo -u happ bash /home/happ/gunicorn_start
Check Supervisor logs for more details:
sudo tail -f /var/log/supervisor/supervisord.log
sudo tail -f /home/happ/logs/gunicorn.log
Ensure Supervisor has access to your environment variables. Modify happ.conf to include the environment directive:
[program:happ]
command=/home/happ/gunicorn_start
user=happ
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/happ/logs/gunicorn.log
stderr_logfile=/home/happ/logs/gunicorn_error.log
environment=DJANGO_SETTINGS_MODULE="happ.settings",PYTHONPATH="/home/happ/happ:$PYTHONPATH"
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.