D
D
DarkByte20152018-01-26 16:50:40
Django
DarkByte2015, 2018-01-26 16:50:40

Running a django app on prod?

I've been trying (for a week now!) to run a django app on prod. Now all the stages have been passed, I'm going to the finish line! :D I can run the application normally with gunicorn, nginx distributes static, everything is ok. Now I need it to actually work all the time, and not just when I launched it from the console. Googled a lot of different daemons for this (monitoring the running of the hunicorn), but I liked runit the most . Everything is very simple - a sh script is thrown, in which a command is set to run. What seemed especially convenient to me is that it is the script here, and not the config. You can set variables for the command (it is rather long).
So here's the problem: it either works or it doesn't. Sometimes I launch and everything works the first time. Then I change something (not in the runit script, but in the project or nginx config) and it stops running. :( And manually from the console, I can still run the gunicorn without problems. And even when I just run this same sh script from the console (which should run runit), it works fine.But when I try to do "sv start myapp" (or restart) it says "timeout: down: myapp: 1s, normally up, want up" or even more interestingly "ok: run: myapp: (pid 49720) 0s", but this does not run anything and the status remains down (you can check with sv status myapp or look in the stat file that runit creates). Most importantly, I don’t understand if he writes any logs? Where can you see them? The syslog is empty. How to understand what he needs? Why sometimes it starts normally, and sometimes it's stupid?
This is how my run (run script for runit) looks like:

#!/bin/sh

GUNICORN=/root/.virtualenvs/certificate_generator/bin/gunicorn
ROOT=/var/www/sup78user/data/www/certificate_generator
PID=$ROOT/run/gunicorn.pid
ACCESS_LOG=$ROOT/logs/gunicorn-access.log
ERROR_LOG=$ROOT/logs/gunicorn-error.log

APP=certificate_generator.wsgi:application

if [ -f $PID ]; then rm $PID; fi

exec $GUNICORN \
    --access-logfile $ACCESS_LOG \
    --error-logfile $ERROR_LOG \
    --pid $PID \
    --bind :8000 \
    --chdir $ROOT \
    $APP

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question