Reputation: 2687
I'm building a django project (mailman3) and accessing it with uwsgi. I have it running successfully when launching uwsgi within the virtualenv from the command line.
I'm trying to build a systemd service to manage uwsgi. It successfully loads the virtual environment for uwsgi and runs. But when it tries to run the django process with attach-daemon, manage.py can't find the django module, i.e., it's not picking up the virtual environment.
In the /etc/uwsgi.ini file I have:
virtualenv = /opt/mailman/venv
chdir = /opt/mailman/mailman-suite/mailman-suite_project
attach-daemon = ./manage.py qcluster
The systemd service has:
ExecStart=/opt/mailman/venv/bin/uwsgi --ini /etc/uwsgi.ini
When systemd starts the service, my error log reports:
[...]
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x558c5945bc30 pid: 15392 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 15392)
spawned uWSGI worker 1 (pid: 15416, cores: 2)
Traceback (most recent call last):
File "./manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
Upvotes: 0
Views: 480
Reputation: 2687
Here's the puzzle piece:
It worked running locally with the virtualenv active. But when run by systemd, even using uwsgi from within the virtualenv, the attach-daemon process would not inherit the virtualenv.
Changing the config line to the following enables the virtualenv:
attach-daemon = /opt/mailman/venv/bin/python3 ./manage.py qcluster
Upvotes: 0