Skip to content

Instantly share code, notes, and snippets.

@mau21mau
Last active May 15, 2019 18:02
Show Gist options
  • Save mau21mau/611817aaf9e2692a3f52c6f1e3a6af3f to your computer and use it in GitHub Desktop.
Save mau21mau/611817aaf9e2692a3f52c6f1e3a6af3f to your computer and use it in GitHub Desktop.
UWSGI + Django Ubuntu >= 16.04

Install Python3 base stuff

sudo apt-get install python3-dev
sudo apt-get install python3-setuptools
sudo apt-get install python3-kivy

Install Pip

wget 'https://bootstrap.pypa.io/get-pip.py'
python get-pip.py

Install UWSGI

sudo pip install uwsgi

Now we need to create the vassals folder, which is the folder where our .ini files (called vassals) will reside upon. Inside vassals we will have two other folders: available and enabled. The first will contain all the (.ini) configuration files. While the second (enabled) will contain a symlink to the files at available.
1:

cd /etc/

2:

sudo mkdir uwsgi

3:

cd uwsgi

4:

sudo mkdir vassals

5:

cd vassals

6:

sudo mkdir enabled

7:

sudo mkdir available

Now we need to create an emperor.ini file, which will contain the path for the other vassals at enabled:

sudo nano /etc/uwsgi/vassals/emperor.ini

Add this to the file:

[uwsgi]
emperor = /etc/uwsgi/vassals/enabled

###Now, it's time to deamonize uwsgi. In order to do it, create a usgi.service file at /etc/systemd/system/:

sudo nano /etc/systemd/system/uwsgi.service

Now, paste the following content into it:

[Unit]
Description=uWSGI Emperor
After=syslog.target

[Service]
ExecStart=/usr/local/bin/uwsgi --ini /etc/uwsgi/vassals/emperor.ini
# Requires systemd version 211 or newer
RuntimeDirectory=uwsgi
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target

Save the file, and run the following commands:

  1. To start the service
sudo systemctl start uwsgi
  1. Check that it started without issues by typing:
systemctl status uwsgi
  1. If there were no errors, enable the service so that it starts at boot by typing:
sudo systemctl enable uwsgi
  1. If there were no errors, enable the service so that it starts at boot by typing:
sudo systemctl stop uwsgi

This is an example of a .ini file for the vassals:

[uwsgi]
# Path to the virtualenv folder
home = /home/maumau/.virtualenvs/sendmail
#socket = 127.0.0.1:8000
socket  = /tmp/sendmail.sock
uid = www-data
gid = www-data
processes = 5
#harakiri=20
#max-requests=1000
#vacum=True
chmod-socket = 666
buffer-size=32768
# Esta a pasta do projeto
# Django project root (manage.py)
chdir = /home/maumau/webapps/sendmail
logto = /var/log/uwsgi/sendmail.log
module = sendmail.wsgi
@EugeneDae
Copy link

What's the purpose of python3-kivy here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment