zeoni_coder
zeoni_coder

Reputation: 1

systemctl and uwsgi issue for remote django app

when I run uwsgi manually with uwsgi --ini uwsgi.ini command, it runs properly, but when I run sudo systemctl start uwsgi it will run properly (i.e., journalctl -b -u uwsgi or sudo systemctl status uwsgi won't show any errors) but I will get 500 error for all API calls. The errors do not happen when I run the server manually. And the uwsgi.service file worked fine until this morning so I don't know what is happening all of a sudden. help me please? The remote server is an ubuntu machine.

I tried relaxing the permissions of related files/directories etc, doesn't work. When I check the uwsgi log it says that django app was not found, but I'm pretty sure the env files/variables are correctly configured. It works fine when I run uwsgi manually too.

Set PythonHome to /home/ubuntu/venv3.9
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x557b93f7ebf0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145840 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
Traceback (most recent call last):
  File "/home/ubuntu/[app]/wsgi.py", line 14, in <module>
    application = get_wsgi_application()
  File "/home/ubuntu/venv3.9/lib/python3.9/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
    django.setup(set_prefix=False)
  File "/home/ubuntu/venv3.9/lib/python3.9/site-packages/django/__init__.py", line 19, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/home/ubuntu/venv3.9/lib/python3.9/site-packages/django/conf/__init__.py", line 102, in __getattr__
    self._setup(name)
  File "/home/ubuntu/venv3.9/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in _setup
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 569090)
spawned uWSGI worker 1 (pid: 569097, cores: 1)
spawned uWSGI http 1 (pid: 569098)
--- no python application found, check your startup logs for errors ---
[pid: 569097|app: -1|req: -1/1] 127.0.0.1 () {60 vars in 1306 bytes} [Sat Jun  8 20:41:13 2024] POST /api/user/login/ => generated 21 bytes in 0 msecs (HTTP/1.0 500) 2 headers in 83 bytes (0 switches on core 0)

here is my uwsgi.ini file:

[uwsgi]
chdir = /home/ubuntu/"project_home"
module = "project_name".wsgi:application
home = /home/ubuntu/venv3.9
http = 0.0.0.0:8000
master = true
vacuum = true
# pidfile = /home/ubuntu/"project_home"/.config/uwsgi/uwsgi.pid
pidfile = /home/ubuntu/.uwsgi/uwsgi.pid
logto = /var/log/uwsgi:"my_project".log
for-readline = /home/ubuntu/"project_home"/.config/uwsgi/env
  env = %(_)
endfor =
uid = ubuntu
gid = www-data

here is my env file:

export DJANGO_SETTINGS_MODULE="my_project".settings.production
export DB_PASSWORD='password'
export EMAIL_HOST_PASSWORD='password_'
export SECRET_KEY="secret_key"

here is my uwsgi.service file:

[Unit]

Description=uWSGI Emperor service
After=syslog.target

[Service]
ExecStart=/home/ubuntu/venv3.9/bin/uwsgi --ini /home/ubuntu/"my_project"/.config/uwsgi/uwsgi.ini

RuntimeDirectory=uwsgi
Restart=on-failure
KillSignal=SIGQUIT
Type=simple
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target

Just reiterating, when I run `

/home/ubuntu/venv3.9/bin/uwsgi --ini /home/ubuntu/"my_project"/.config/uwsgi/uwsgi.ini

manually, it works fine. the server works. but when I try to do that through systemctl it prints out the error that I copied to the first code block.

Upvotes: 0

Views: 37

Answers (0)

Related Questions