I'm deploying a django project on digital ocean. My project has the following structure:
$/
flo-log/
logistics/
settings.py
wsgi.py
...
manage.py
...
My project gunicorn fille is shown below:
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=flolog
Group=flolog
WorkingDirectory=/home/flolog/flo-log/logistics
ExecStart=/home/flolog/flologenv/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
logistics.wsgi:application
[Install]
WantedBy=multi-user.target
I created a user with sudo privilege. Whenever I run sudo systemctl status gunicorn I encountered ModuleNotFoundError: no module named logistics.
And from the details of the error, it's due to the logistics.wsgi: application component of gunicorn service file
The error stated that there's no module called logistics however,I have a directory called logistics which contains the wsgi file. Please how do I fix this error? Why is it that they are telling me logisticsbis not a directory. Better still, how do I set myproject.wsgi section of gunicorn service file properly based on my project structure
I would say just look at your project structure. Remove the flo-log first folder and have Logistics and manage.py inside the home directory of your server as well as your virtual env. The project file "Logistics" should be in the same folder as manage.py inside home.
Hope that helps.
Related
Could you please help me with setting up Gunicorn for Django application? I'm going through clear and great digital ocean tutorial and don't know how to access my wsgi.py file for Gunicorn.
In example it is shown like this:
cd ~/myprojectdir
gunicorn --bind 0.0.0.0:8000 myproject.wsgi
But my wsgi.py file has another address ~/myprojectdir/LibrarySite/locallibrary/wsgi.py. So, I did it this way:
cd ~/myprojectdir/LibrarySite/locallibrary
gunicorn --bind 0.0.0.0:8000 locallibrary.wsgi
I get an error:
No module named 'locallibrary'
I'm sorry for such a dummy question, but what is the correct way to set file address right?
I was trying to run Django in Nginx with the centos7 platform and also I am a newbie to it. After some time, I configured Django in Nginx with the help of the gunicorn service, But suddenly gunicorn service stopped with an unrecognized argument error (WSGI).
enter image description here
and my gunicorn service file:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=user
Group=nginx
WorkingDirectory=/home/websitehg/websites/qatarfactory/qf_project
ExecStart=/home/websitehg/websites/qatarfactory/qf_env/bin/gunicorn --workers 3 --reload true --bind unix:/home/websitehg/websites/qatarfactory/qf_project/qf_project.sock qf_project.wsgi:app
[Install]
WantedBy=multi-user.target
I don't know what's wrong with it
I added threads to it, Problem solved for me
--threads=3
I want some help to fix this issue. myproject.wsgi in gunicorn is not recognised.
I created a user flolog with sudo privileges. My project structure is as follows (the first directory i created is flo-log and it contains other directories in d django app):
:~/
flo-log/
account/
logistics/
settings.py
wsgi.py
...
manage.py
...
flologenv/
requirements.txt
Content of gunicorn file is:
How do I fix it? Or is there any resources that can help?
it is difficult to define the problem without your project structure, but seems to me in the working directory you give the path to app folder, but not to root folder. Here are my settings which could help you to configure your wsgi. "conf" is the name of app with settings and asgi wsgi files.
sudo vim /etc/systemd/system/gunicorn.sock
[Unit]
Description=Gunicorn daemon for Django Project
Before=nginx.service
After=network.target
[Service]
WorkingDirectory=/home/www/app/root_folder
ExecStart=/home/www/app/venv/bin/gunicorn --access-logfile - --workers 3 --log-level debug --bind unix:/home/www/app/root_folder/conf.sock conf.wsgi:application
Restart=always
SyslogIdentifier=gunicorn
User=root
Group=www-data
[Install]
WantedBy=multi-user.target
Trying to deploy django application using gunicorn and nginx on CentOS. Following DigitalOcean tutorial:
https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-centos-7
But I have CentOS 8.
I can run my application locally from virtualenv using:
python manage.py runserver
gunicorn --bind 0.0.0.0:8000 app.wsgi:application
but then I try to run gunicorn.service I have status - failed.
Inside of systemctl status gunicorn.service I have
started gunicorn deamon
gunicorn.service: main process exited, code=exited, status=203/EXEC
gunicorn.service: failed with result 'exit-code'
Without this file I can't bind app.sock file as it not being created.
My gunicorn.service looks like this
app - is fictional application name :)
admin - is a real user of this system
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=admin
Group=nginx
WorkingDirectory=/home/admin/app/portal/app
ExecStart=/home/admin/app/env/bin/gunicorn --workers 3 --bind unix:/home/admin/app/portal/app/app.sock app.wsgi:application
[Install]
WantedBy=multi-user.target
There is a tree of my project:
app
- env
- portal
-- client
-- app
--- documents
--- fixtures
--- images
--- app
---- __init__.py
---- settings.py
---- urls.py
---- wsgi.py
--- app_project
---- ...
--- manage.py
--- requirements.txt
What can be done to make it work and that can I check to find more clues why it doesn't work?
Any input is welcome.
Thanks
in journalctl -xe
I've noticed
SELinux is preventing file/path from execute access on the file
so I changed
SELINUX=permissive
in /etc/selinux/config
rebooted and now I have different error in systemctl status gunicorn.service:
gunicorn: error: unrecognized arguments: app.wsgi:application
oh, that was because I added additional flag to ExecStart. Removed it and it works now.
So issue was with SELinux.
Will keep it here in case if it would be useful to anyone
I have two django projects running on different ports in same ec2 instance, One I have configured with gunicorn system as follows by creating gunicorn.service file at /etc/systemd/system/ which is working awesome if I run the command systemctl start gunicorn. Now I want to run another proect, how can I configure it, currently I am running that using gunicorn command /usr/local/bin/gunicorn --graceful-timeout 30 --bind 0.0.0.0:8690 projectFile.wsgi:application --daemon, Can I add same in gunicorn.service itself. How do I configure multiple projects in gunicorn systemd?
gunicron.service file -
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
PIDFile=/tmp/gunicorn.pid
LogFile=/tmp/lgunicorn.log
User=root
Group=www-data
WorkingDirectory=/home/ubuntu/website/UniservedWebsite
ExecStart = /usr/local/bin/gunicorn --workers 2 --graceful-timeout 30 --bind 0.0.0.0:8134 UniservedWebsite.wsgi:application
[Install]
WantedBy=multi-user.target
Just create two .service file, and start them separately...