summaryrefslogtreecommitdiff
path: root/tech/set up uwsgi django.txt
diff options
context:
space:
mode:
Diffstat (limited to 'tech/set up uwsgi django.txt')
-rw-r--r--tech/set up uwsgi django.txt82
1 files changed, 82 insertions, 0 deletions
diff --git a/tech/set up uwsgi django.txt b/tech/set up uwsgi django.txt
new file mode 100644
index 0000000..37df453
--- /dev/null
+++ b/tech/set up uwsgi django.txt
@@ -0,0 +1,82 @@
+How to Set Up Django with uWSGI on Debian 8
+
+First make sure uWSGI is installed in the virtualenv.
+
+virt && pip install uwsgi
+
+Then because we want to start an emperor with systemd so that the server will come back up on reboot we need the global version installed as well.
+
+Because I set pip to require a virtualenv by default I have to first disable that:
+
+PIP_REQUIRE_VIRTUALENV=false
+
+Then:
+
+pip install uwsgi
+
+Now we need a systemd service file. Here's what I use (again, the path is the standard Debian install locations, your system may vary, though I believe Ubuntu is the same)
+
+[Unit]
+Description=uWSGI Emperor
+After=syslog.target
+
+[Service]
+ExecStart=/usr/local/bin/uwsgi --ini /etc/uwsgi/emperor.ini
+Restart=always
+KillSignal=SIGQUIT
+Type=notify
+StandardError=syslog
+NotifyAccess=all
+
+[Install]
+WantedBy=multi-user.target
+
+Save that to /lib/systemd/system/uwsgi.service
+
+Then try starting it:
+
+sudo systemctl start uwsgi
+
+This should cause an error like so...
+
+Job for uwsgi.service failed. See 'systemctl status uwsgi.service' and '' for details.
+
+If you look at the journal you'll see that the problem is that uwsgi can't find the emperor.ini file in our service file. So, let's create that file.
+
+Most likely the directory /etc/uwsgi doesn't exist so create that and then the emperor.ini file in it:
+
+mkdir /etc/uwsgi
+vim /etc/uwsgi/emperor.ini
+
+Here's the contents of my emperor.ini:
+
+[uwsgi]
+emperor = /etc/uwsgi/vassals
+uid = www-data
+gid = www-data
+limit-as = 1024
+logto = /tmp/uwsgi.log
+
+The last step is to create the vassals directory we just reference in emperor.ini:
+
+sudo mkdir /etc/uwsgi/vassals
+
+Now go back and try starting again:
+
+sudo systemctl start uwsgi
+
+That should work. Then stop it and add it to systemd so it will startup with the system:
+
+sudo systemctl stop uwsgi
+sudo systemctl enable uwsgi
+sudo systemctl start uwsgi
+
+uwsgi is now running.
+
+The next step is to add a vassal. To do that just symlink your uwsgi file into /etc/uwsgi/vassals. The exact paths will vary, but something like:
+
+sudo ln -s /path/to/your/project/django.ini /etc/uwsgi/vassals/
+
+Further Reading:
+
+* As mentioned above, [this gist](https://gist.github.com/evildmp/3094281) covers how to setup the Django end of the equation and covers more of what's actually happening in this setup.