soubhagya
soubhagya

Reputation: 806

Error in django Gunicorn server hosted on aws ec2

erroor after sudo journalctl -u gunicorn command

    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]: [2019-01-03 16:22:43 +0000] [10432] [ERROR] Exception in worker process
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]: Traceback (most recent call last):
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:   File "/home/ubuntu/monetimes/env/lib/python3.5/site-packages/gunicorn/arbiter.py", line 583, in sp
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:     worker.init_process()
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:   File "/home/ubuntu/monetimes/env/lib/python3.5/site-packages/gunicorn/workers/base.py", line 129, 
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:     self.load_wsgi()
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:   File "/home/ubuntu/monetimes/env/lib/python3.5/site-packages/gunicorn/workers/base.py", line 138, 
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:     self.wsgi = self.app.wsgi()
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:   File "/home/ubuntu/monetimes/env/lib/python3.5/site-packages/gunicorn/app/base.py", line 67, in ws
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:     self.callable = self.load()
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:   File "/home/ubuntu/monetimes/env/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 52, in
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:     return self.load_wsgiapp()
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:   File "/home/ubuntu/monetimes/env/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 41, in
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:     return util.import_app(self.app_uri)
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:   File "/home/ubuntu/monetimes/env/lib/python3.5/site-packages/gunicorn/util.py", line 350, in impor
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:     __import__(module)
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]: ImportError: No module named 'monetimes'
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]: [2019-01-03 16:22:43 +0000] [10432] [INFO] Worker exiting (pid: 10432)
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]: [2019-01-03 16:22:43 +0000] [10433] [INFO] Booting worker with pid: 10433
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]: [2019-01-03 16:22:43 +0000] [10433] [ERROR] Exception in worker process
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]: Traceback (most recent call last):
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:   File "/home/ubuntu/monetimes/env/lib/python3.5/site-packages/gunicorn/arbiter.py", line 583, in sp
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:     worker.init_process()
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:   File "/home/ubuntu/monetimes/env/lib/python3.5/site-packages/gunicorn/workers/base.py", line 129, 
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:     self.load_wsgi()
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:   File "/home/ubuntu/monetimes/env/lib/python3.5/site-packages/gunicorn/workers/base.py", line 138, 
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:     self.wsgi = self.app.wsgi()
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:   File "/home/ubuntu/monetimes/env/lib/python3.5/site-packages/gunicorn/app/base.py", line 67, in ws
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:     self.callable = self.load()
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:   File "/home/ubuntu/monetimes/env/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 52, in
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:     return self.load_wsgiapp()
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:   File "/home/ubuntu/monetimes/env/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 41, in
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:     return util.import_app(self.app_uri)
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:   File "/home/ubuntu/monetimes/env/lib/python3.5/site-packages/gunicorn/util.py", line 350, in impor
    Jan 03 16:22:43 ip-172-31-27-161 gunicorn[10426]:     __import__(module)

gunicorn file

    [Unit]
    Description=gunicorn daemon
    After=network.target

    [Service]
    User=ubuntu
    Group=www-data
    WorkingDirectory=/home/ubuntu/monetimes
    ExecStart=/home/ubuntu/monetimes/env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/ubuntu/monetimes/src/monetimes.sock monetimes.wsgi:app$

    [Install]
    WantedBy=multi-user.target

my-django structure is:

    monetimes:
        env
        src:
            monetimes:
                __init__.py
                urls.py
                wsgi.py
            landing
            static_files
            templates
            media
            db.sqlite3
            requirements.txt
            manage.py

django aws gunicorn error inside ec2 instance. i have gunicorn inside my virtualenv .

i have shared all the files and codes.

when i am checking the status sudo systemctl status gunicorn it is working but when i am adding below command i am getting above errors.

sudo journalctl -u gunicorn

please have a look into my code.

Upvotes: 1

Views: 624

Answers (1)

Will Keeling
Will Keeling

Reputation: 22994

Try adding the monetimes/src directory to the PYTHONPATH via an Environment setting:

[Service]
    User=ubuntu
    Group=www-data
    WorkingDirectory=/home/ubuntu/monetimes
    ExecStart=/home/ubuntu/monetimes/env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/ubuntu/monetimes/monetimes.sock monetimes.wsgi:app$
    Environment="PYTHONPATH=/home/ubuntu/monetimes/src"

Upvotes: 3

Related Questions