Skip to content
Advertisement

Difference between Daemon and Upscript for Gunicorn in Django Production

I am deploying a Django site in production and now from a week I couldn’t get Gunicorn script in /etc/init/project.conf to bind Nginx no matter what I do inside a Django virtual environment and under newly created user djagno at location /home/Django/project/bin/gunicorn. I need to know that can I run a site in production with daemon. I understand that daemon is simply a background process and not attached to any tty. But with creating a pid with running a command from inside a virtualenv like “gunicorn –bind 127.0.0.1:9500 project.wsgi:application –config=/etc/gunicorn.d/gunicorn.py –name=project -p /tmp/project.pid” wouldn’t it act as a service? My project without virtual environment is working just fine but not with virtual environment. I am learning Linux so need an expert advise. Can I launch a project like this?

My upstart script I couldn’t attach within virtualenv is given below.

description "Gunicorn daemon for Django project"

start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]

# If the process quits unexpectadly trigger a respawn
respawn

setuid django
setgid django
chdir /home/django

exec gunicorn 
    --name=project
    --pythonpath=project
    --bind=127.0.0.1:9500 
    --config /etc/gunicorn.d/gunicorn.py 
    project.wsgi:application

If someone can help me to make change in it according to virtualenv I would be thankful. Again…same settings for my project without virtualenv are working just fine but not for my second website where the only difference is that I am running first project without virtualenv and second one is from virtualenv.

Advertisement

Answer

The point is that if you just run it like that, you don’t have anything responsible for ensuring it remains up: if the process dies, or if you have to restart your server, you will have to re-run that command manually. That’s what upstart, or supervisor, will do for you: monitor that it is indeed running, and bring it back if it isn’t.

If you want help with debugging your upstart script, you will need to actually post it, plus any errors from the log.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement