17

I am trying to follow this tutorial to setup uWSGI with Django and nginx on Ubuntu16.04.

It all works fine up until the very last step (oh the irony...) where I try to execute this command:

sudo service uwsgi start 

If fails with the following error:

Failed to start uwsgi.service: Unit uwsgi.service not found.

Others seem to get a similar error:

Failed to start uwsgi.service: Unit uwsgi.service failed to load: No such file or directory.

The issue appears to be related to the version of Ubuntu. While that tutorial is aimed at Ubuntu 14.04, it seems it will not work for newer versions because in version 15 Ubuntu switched from the upstart init daemon to the systemd init daemon.

How can I use systemd to launch uWSGI so that it works with nginx and Django?

2 Answers 2

30

The first modification needed is to the /etc/uwsgi/sites/firstsite.ini file. The only change needed is replacing the permissions from 664 to 666. The script would look like this:

[uwsgi] project = firstsite base = /home/user chdir = %(base)/%(project) home = %(base)/Env/%(project) module = %(project).wsgi:application master = true processes = 5 socket = %(base)/%(project)/%(project).sock chmod-socket = 666 vacuum = true 

Secondly, as we're using systemd rather than upstart, the following file is not needed and can be removed: /etc/init/uwsgi.conf

Third, we create the following systemd script at /etc/systemd/system/uwsgi.service:

[Unit] Description=uWSGI Emperor service After=syslog.target [Service] ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/sites Restart=always KillSignal=SIGQUIT Type=notify StandardError=syslog NotifyAccess=all [Install] WantedBy=multi-user.target 

Refresh the state of the systemd init system with this new uWSGI service on board

sudo systemctl daemon-reload 

In order to start the script you'll need to run the following:

sudo systemctl start uwsgi 

In order to start uWSGI on reboot, you will also need:

sudo systemctl enable uwsgi 

You can use the following to check its status:

systemctl status uwsgi 

Some further details can be found here.

3
  • 1
    How do you make systemd use a python virtualenv? When I run systemctl status uwsgi I get ImportError: No module named site. Commented Jun 2, 2016 at 1:00
  • 2
    epic..... i was struggling for so long with this.... thank you for the straight-forward easy step-by-step solution you have written here. +1 Commented Aug 30, 2016 at 4:06
  • 1
    I used it a few times ,very helpful answer Commented Dec 6, 2016 at 15:33
0

To get around that error: sudo systemctl daemon-reload for the newly created uwsgi.service file to be loaded.

To make service start on each reboot: sudo systemctl enable uwsgi.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.