The wsgi project was not found at startup automatically, but not manually

I don’t understand why I got an error in that I did not find my project.wsgi module when the supervisor tries to start the application automatically (for example, when the server starts.)

2014-02-15 05:13:05 [1011] [INFO] Using worker: sync
2014-02-15 05:13:05 [1016] [INFO] Booting worker with pid: 1016
2014-02-15 05:13:05 [1016] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/var/local/sites/myproject/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
    worker.init_process()
  File "/var/local/sites/myproject/venv/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
    self.wsgi = self.app.wsgi()
  File "/var/local/sites/myproject/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
    self.callable = self.load()
  File "/var/local/sites/myproject/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
    return self.load_wsgiapp()
  File "/var/local/sites/myproject/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/var/local/sites/myproject/venv/local/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
    __import__(module)
ImportError: No module named myproject.wsgi

While I am not getting this error, and it works fine when I do it manually:

sudo supervisorctl start myapp

What is the difference?

thanks

UPDATE:

confisor conf file:

[program:myproject]
command=/var/local/sites/myproject/run/gunicorn_start                       ; Command to start app
user=myproject                                             ; User to run as
autostart=true
autorestart=true
loglevel=info
redirect_stderr=false
stdout_logfile=/var/local/sites/myproject/logs/supervisor-myproject-stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/var/local/sites/myproject/logs/supervisor-myproject-stderr.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB

/ var / local / sites / MyProject / run / gunicorn_start:

#!/bin/bash

NAME="myproject_app"         # Name of the application
USER=myproject          # the user to run as
GROUP=myproject        # the group to run as

NUM_WORKERS=3                       # how many worker processes should Gunicorn spawn

# Logs config
LOG_LEVEL=info
ACCESS_LOGFILE=/var/local/sites/myproject/logs/gunicorn-myproject-access.log
ERROR_LOGFILE=/var/local/sites/myproject/logs/gunicorn-myproject-error.log

echo "Starting $NAME"        

exec envdir /var/local/sites/myproject/env_vars /var/local/sites/myproject/venv/bin/gunicorn myproject.wsgi:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER --group=$GROUP \
  --log-level=$LOG_LEVEL \
  --bind=unix:/tmp/myproject.gunicorn.sock \
  --access-logfile=$ACCESS_LOGFILE \
  --error-logfile=$ERROR_LOGFILE
+4
source share
3 answers

I think you should add directorya supervisor to your configuration file. This is my template. I use this in every project and work great:

[program:PROJECT_NAME]
command=/opt/sites/PROJECT_NAME/env/bin/gunicorn -c /opt/sites/etc/gunicorn/GUNICORN_CONF.conf.py PROJECT_NAME.wsgi:application
directory=/opt/sites/PROJECT_NAME
environment=PATH="/opt/sites/PROJECT/env/bin"
autostart=true
autorestart=false
redirect_stderr=True
stdout_logfile=/tmp/PROJECT_NAME.stdout
+2
source

. gunicorn_start envdir. django env, /env/nafd/, django /env/nafd/nafd_proj

..
DJANGODIR=/to/path/app_proj
cd $DJANGODIR
source ../bin/activate`

exec ../bin/gunicorn nafd_proj.wsgi:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER --group=$GROUP \
  --log-level=$LOG_LEVEL \
  --bind=unix:/tmp/myproject.gunicorn.sock \
  --access-logfile=$ACCESS_LOGFILE \
  --error-logfile=$ERROR_LOGFILE`
0

, :

, "supervisord" ( ).

, , Flask WSGI (Gunicorn), Supervisor, .

root@ilg40:~# ll /etc/tdm/flask/
total 1120
drwx------ 5 root root   4096 Jan 24 19:47 ./
drwx------ 3 root root   4096 Jan 23 00:20 ../
-r-------- 1 root root   1150 Aug 31 17:54 favicon.ico
drw------- 2 root root   4096 Jan 13 22:51 static/
-rw------- 1 root root 883381 Jan 23 20:09 tdm.log
-rwx------ 1 root root  73577 Jan 23 21:37 tdm.py*
-rw------- 1 root root  56445 Jan 23 21:37 tdm.pyc
drw------- 2 root root   4096 Jan 23 20:08 templates/
-rw-r--r-- 1 root root    493 Jan 23 22:42 wsgi.py
-rw-r--r-- 1 root root    720 Jan 23 22:42 wsgi.pyc
srwxrwxrwx 1 root root      0 Jan 24 19:47 wsgi.sock=

Supervisor

root@ilg40:~# cat /etc/supervisor/conf.d/wsgi_flask.conf 
[program:wsgi_flask]
command = gunicorn --preload --bind unix:/etc/tdm/flask/wsgi.sock --workers 4 --pythonpath /etc/tdm/flask wsgi 
process_name = wsgi_flask
autostart = true
autorestart = true
stdout_logfile = /var/log/wsgi_flask/wsgi_flask.out.log
stderr_logfile = /var/log/wsgi_flask/wsgi_flask.err.log

Supervisord

root@ilg40:~# supervisorctl update
wsgi_flask: added process group

root@ilg40:~# supervisorctl status wsgi_flask
wsgi_flask                       RUNNING    pid 1129, uptime 0:29:12

Note: in the above setup I do not use virtualenv, and I believe that this process may require configuration of the directory variable , as well as setting up the PATH environment for the command variable (adding env PATH = "$ PATH: / the / app / path" gunicorn ...) because this gunner, flask, etc. located inside the virtual.

0
source

Source: https://habr.com/ru/post/1527059/


All Articles