NOTE: Upgrade Ubuntu to 16.04.
The Ubuntu upgrade went smootly, but webserver hosting Python apps is no longer working.
Remove Upstarted Config
I am guessing the main reason is I was using Upstarted for uwsgi on Ubuntu 16.04, and Upstarted is depcreated on 16.04.
Disable the old config file.
sudo mv /etc/init/uwsgi.conf /etc/init/uwsgi.conf.disabledCheck to make sure no uwsgi instance is running.
ps -fC uwsgiIf uwsgi instances are running, restart the server.
NOTE: Why uwsgi still run if Upstarted is deprecated? Refer to SysV, Upstart and systemd init script coexistence.
Check uWSGI
Check version, make sure to be running at least 2.0.18.
uwsgi --versionUpgrade to latest version.
sudo -H pip install uwsgiSetup uWSGI via Systemd
Based on Running uWSGI via Systemd (Ubuntu 16.04).
Setup a emperor.uwsgi service.
sudo nano /etc/systemd/system/emperor.uwsgi.service[Unit]
Description=uWSGI Emperor
After=network.target
[Service]
Group=www-data
ExecStart=/usr/local/bin/uwsgi --ini /etc/uwsgi/emperor.ini
# Requires systemd version 211 or newer
RuntimeDirectory=uwsgi
RuntimeDirectoryMode=0775
Restart=always
KillSignal=SIGQUIT
Type=notify
# dont log to syslog, follow logto
# StandardError=syslog
NotifyAccess=all
[Install]
WantedBy=multi-user.targetCreate /etc/uwsgi/emperor.ini as uwsgi configuration file.
cd /etcsudo mkdir uwsgicd uwsgisudo nano emperor.ini[uwsgi]
emperor = /etc/uwsgi/vassals
uid = www-data # do-user for convinience on DigitalOceans server
gid = www-data
logto = /var/log/uwsgi/emperor.log
logfile-chown = www-data:www-data # do-user:www-data for convinience on DigitalOceans serverNOTE: Assume you already have an existing uWSGI app configuration file at /etc/uwsgi/vassals/.
Start uwsgi.
sudo service emperor.uwsgi startCheck logs for error.
sudo tail -f /var/log/uwsgi/myapp.logsudo tail -f /var/log/nginx/error.logsudo tail -f /var/log/nginx/access.logNOTE: If you bump into the following error, it might be due to previous Upstarted script (e.g. /etc/init/uwsgi.conf) are still running. Disable the script and restart the server.
thunder lock: disabled (you can enable it with --thunder-lock)
error removing unix socket, unlink(): Operation not permitted [core/socket.c line 198]
bind(): Address already in use [core/socket.c line 230]NOTE: If there is a change of permission for log access, you might want to delete old log files to make sure new log files can be created with the appropriate permission.
Enable the service (autostart when system boot).
sudo systemctl enable emperor.uwsgi