summaryrefslogtreecommitdiff
path: root/tech/set up uwsgi django.txt
blob: 37df453c2253a21dd45b2c21d14623567e90060d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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.