Starting a Django Web App as a Service using nginx and uWSGI fails

I have a simple web app that I am trying to run under Ubuntu 22.04 using Django, NGINX, and uWSGI. There is a service for my application which essentially starts uWSGI. If I start the service, uWSGI fails to start. If I run manually, it works perfectly. I can connect from a remote client and get the web page. So why am I having a problem running as a service?

[uwsgi]
chdir = /srv/dlnWebProject/dlnWebApplication
module = dlnWebApplication.wsgi:application
home = /srv/dlnWebProject/dlnWebApplication/.virtualenvs/dlnWebApplication
master = true
processes = 4

# Use HTTP socket
http = 127.0.0.1:8000  # Or use a Unix socket with a full path

die-on-term = true
logto = /var/log/uwsgi/dlnWebApplication.log
log-5xx = true
log-4xx = true
log-level = debug  # Optional for more detailed logs

Here is my service file:

[Unit]
Description=uWSGI instance to serve dlnWebApplication
After=network.target

[Service]
User=www-data  # Replace with the user that should run the service
Group=www-data  # Replace with the appropriate group
WorkingDirectory=/srv/dlnWebProject/dlnWebApplication
Environment="PATH=/srv/dlnWebProject/dlnWebApplication/.virtualenvs/dlnWebApplication/bin"
ExecStart=/srv/dlnWebProject/dlnWebApplication/.virtualenvs/dlnWebApplication/bin/uwsgi --ini /srv/dlnWebProject/dlnWebApplication/uwsgi.ini --uid www-data --gid www-data

[Install]
WantedBy=multi-user.target

This starts and runs uwsgi and allows remote clients to connect and responds with the web page:

sudo -u www-data /srv/dlnWebProject/dlnWebApplication/.virtualenvs/dlnWebApplication/bin/uwsgi --ini /srv/dlnWebProject/dlnWebApplication/uwsgi.ini

Starting as a Service gives: Oct 17 17:51:56 dlnServer systemd[1]: Started uWSGI instance to serve dlnWebApplication. ░░ Subject: A start job for unit dlnWebApplication.service has finished successfully ░░ Defined-By: systemd ░░ Support: http://www.ubuntu.com/support ░░ ░░ A start job for unit dlnWebApplication.service has finished successfully. ░░ ░░ The job identifier is 9072.

Oct 17 17:51:56 dlnServer systemd[18975]: dlnWebApplication.service: Failed to determine user credentials: No such process
Oct 17 17:51:56 dlnServer sudo[18969]: pam_unix(sudo:session): session closed for user root
Oct 17 17:51:56 dlnServer systemd[18975]: dlnWebApplication.service: Failed at step USER spawning /srv/dlnWebProject/dlnWebApplication/.virtualenvs/dlnWebApplication/bin/uwsgi: No such process
Вернуться на верх