Skip to content

Commit 84f717e

Browse files
author
Benjamin
committed
Added instruction commands for setting up uWSGI
1 parent cee9175 commit 84f717e

File tree

1 file changed

+63
-0
lines changed
  • section9/lectures/140_setting_up_uWSGI_to_run_our_REST_API

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
## Setting up uWSGI
2+
This guide will help you set up uWSGI on your server to run the items rest app. Go to the items-rest directory we created in the previous lecture.
3+
4+
```bash
5+
cd /var/www/html/items-rest
6+
```
7+
8+
### Create Ubuntu service
9+
Run the following command to create a service file.
10+
11+
```bash
12+
sudo vi /etc/systemd/system/uwsgi_items_rest.service
13+
```
14+
15+
Copy and paste the following to the file. Note "jose:1234" is the username:password combination of the Postgres user we created before. Change yours accordingly.
16+
17+
```bash
18+
[Unit]
19+
Description=uWSGI items rest
20+
21+
[Service]
22+
Environment=DATABASE_URL=postgres://jose:1234@localhost:5432/jose
23+
ExecStart=/var/www/html/items-rest/venv/bin/uwsgi --master --emperor /var/www/html/items-rest/uwsgi.ini --die-on-term --uid jose --gid jose --logto /var/www/html/items-rest/log/emperor.log
24+
Restart=always
25+
KillSignal=SIGQUIT
26+
Type=notify
27+
NotifyAccess=all
28+
29+
[Install]
30+
WantedBy=multi-user.target
31+
```
32+
33+
Replace the uwsgi.ini file contents with the following
34+
35+
```bash
36+
[uwsgi]
37+
base = /var/www/html/items-rest
38+
app = run
39+
module = %(app)
40+
41+
home = %(base)/venv
42+
pythonpath = %(base)
43+
44+
socket = %(base)/socket.sock
45+
46+
chmod-socket = 777
47+
48+
processes = 8
49+
50+
threads = 8
51+
52+
harakiri = 15
53+
54+
callable = app
55+
56+
logto = /var/www/html/items-rest/log/%n.log
57+
```
58+
59+
Finally start the app by running
60+
61+
```bash
62+
sudo systemctl start uwsgi_items_rest
63+
```

0 commit comments

Comments
 (0)