I am trying to follow this tutorial to setup uWSGI
with Django
and nginx
on Ubuntu
16.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?
The first modification needed is to the
/etc/uwsgi/sites/firstsite.ini
file. The only change needed is replacing the permissions from664
to666
. The script would look like this:Secondly, as we're using
systemd
rather thanupstart
, 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
:Refresh the state of the systemd init system with this new uWSGI service on board
In order to start the script you'll need to run the following:
In order to start
uWSGI
on reboot, you will also need:You can use the following to check its status:
Some further details can be found here.
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
.