unbit / uwsgi

uWSGI application server container
http://projects.unbit.it/uwsgi
Other
3.45k stars 691 forks source link

Internal Server Error with Django and uWSGI 2 Emperor mode (ONLY) #650

Closed dghant1024 closed 10 years ago

dghant1024 commented 10 years ago

When I run uswsgi services WITHOUT running it in emperor mode my django website runs just fine. No matter how I change my configuration I always get the error message my /tmp/uwsgi.log file: "--- no python application found, check your startup logs for errors ---" I have listed my configuration and error log below:

OS version: Linux raspberrypi 3.6.11+ #538 armv6l GNU/Linux Django version: 1.6.5 uwsgi version: 2.0.5.1

Virtual environment: /var/www/testbed/env Project location: /var/www/testbed/project/auth project tree:

./auth/
|-- __init__.py
|-- __init__.pyc
|-- requirements.txt
|-- settings.py
|-- settings.pyc
|-- urls.py
|-- urls.pyc
|-- wsgi.py
`-- wsgi.pyc

file wsgi.py:

"""
WSGI config for auth project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
"""
    import os, sys, site

    sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")))
    sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), "../")))
    sys.path.append('/usr/lib/python2.7')
    sys.path.append('/usr/lib/python2.7/dist-packages')

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "auth.settings")

    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()

file /etc/uwsgi/emperor.ini:

[uwsgi]
master = true
emperor = /etc/uwsgi/vassals
logto = /tmp/uwsgi.log

file /etc/uwsgi/vessals/auth.ini:

[uwsgi]
#plugins = python
# Django-related settings
chdir           =/var/www/testbed/project/auth
module          = auth.wsgi:application

# the virtualenv (full path)
home            =/var/www/testbed/env
virtualenv      =/var/www/testbed/env

# process-related settings
enable-threads  = true
pythonpath      = /var/www/testbed/project/auth
#wsgi-file      = /var/www/testbed/project/auth/auth/wsgi.py
env             = DJANGO_SETTINGS_MODULE=auth.settings

mount = /testbed/auth/admin=/var/www/testbed/project/auth/auth/wsgi.py
manage-script-name = true
#route-run = log:SCRIPT_NAME=${SCRIPT_NAME}

# maximum number of worker processes
processes       = 1 #Simple rule is # of cores on machine
# the socket (use the full path to be safe
socket          = /var/www/testbed/project/auth/uwsgi.sock
# ... with appropriate permissions - may be needed
chmod-socket    = 664
# clear environment on exit
vacuum          = true
logto           = /tmp/uwsgi.log

Command being executed listed below:

/var/www/testbed/env/bin/uwsgi --ini /etc/uwsgi/emperor.ini --emperor /etc/uwsgi/vassals/ --http :8000  --plugin python --binary-pathusr/local/bin/uwsgi

Error file /tmp/uwsgi.log:


*** Starting uWSGI 2.0.5.1 (32bit) on [Tue Jun 10 19:06:12 2014] ***
compiled with version: 4.6.3 on 10 June 2014 01:41:52
os: Linux-3.6.11+ #538 PREEMPT Fri Aug 30 20:42:08 BST 2013
nodename: raspberrypi
machine: armv6l
clock source: unix
detected number of CPU cores: 1
current working directory: /etc/uwsgi
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
your processes number limit is 3376
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8000 fd 6
*** starting uWSGI Emperor ***
uwsgi socket 0 bound to TCP address 127.0.0.1:57524 (port auto-assigned) fd 5
Python version: 2.7.3 (default, Mar 18 2014, 05:13:23)  [GCC 4.6.3]
*** has_emperor mode detected (fd: 8) ***
[uWSGI] getting INI configuration from auth.ini
*** Starting uWSGI 2.0.5.1 (32bit) on [Tue Jun 10 19:06:12 2014] ***
compiled with version: 4.6.3 on 09 June 2014 23:07:00
os: Linux-3.6.11+ #538 PREEMPT Fri Aug 30 20:42:08 BST 2013
nodename: raspberrypi
machine: armv6l
clock source: unix
detected number of CPU cores: 1
current working directory: /etc/uwsgi/vassals
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
your processes number limit is 3376
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /var/www/testbed/project/auth/uwsgi.sock fd 3
Python version: 2.7.3 (default, Mar 18 2014, 05:13:23)  [GCC 4.6.3]
Set PythonHome to /var/www/testbed/env
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1dca830
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 128512 bytes (125 KB) for 1 cores
*** Operational MODE: single process ***
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 23068)
spawned uWSGI worker 1 (pid: 23071, cores: 1)
spawned uWSGI http 1 (pid: 23072)
Python main interpreter initialized at 0x616918
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 128512 bytes (125 KB) for 1 cores
*** Operational MODE: single process ***
added /var/www/testbed/project/auth/ to pythonpath.
WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0x616918 pid: 23070 (default app)
mounting /var/www/testbed/project/auth/auth/wsgi.py on /testbed/auth/admin
added /var/www/testbed/project/auth/ to pythonpath.
WSGI app 1 (mountpoint='/testbed/auth/admin') ready in 3 seconds on interpreter 0x9c6218 pid: 23070
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 23070)
Tue Jun 10 19:06:18 2014 - [emperor] vassal auth.ini has been spawned
spawned uWSGI worker 1 (pid: 23073, cores: 1)
Tue Jun 10 19:06:18 2014 - [emperor] vassal auth.ini is ready to accept requests
--- no python application found, check your startup logs for errors ---
[pid: 23071|app: -1|req: -1/1] 192.168.1.6 () {38 vars in 742 bytes} [Tue Jun 10 19:07:11 2014] GET /testbed/auth/admin => generated 21 bytes in 1 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 23071|app: -1|req: -1/2] 192.168.1.6 () {36 vars in 626 bytes} [Tue Jun 10 19:07:11 2014] GET /favicon.ico => generated 21 bytes in 1 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 23071|app: -1|req: -1/3] 192.168.1.6 () {38 vars in 742 bytes} [Tue Jun 10 19:07:13 2014] GET /testbed/auth/admin => generated 21 bytes in 2 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 23071|app: -1|req: -1/4] 192.168.1.6 () {36 vars in 626 bytes} [Tue Jun 10 19:07:13 2014] GET /favicon.ico => generated 21 bytes in 1 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)

At this point, I'm grasping at straws. Out of all the reading that I have done I can't see why this keeps rendering the "Internal Server Error." I may have over looked something that why I've finally given in to my pride by posting my sorrows here. Since I've gotten this far I really do think that I have overlooked something very small. Any help would be greatly appreciated.

unbit commented 10 years ago

sorry, but the config is completely wrong, i fear you do not have a clear situation about the Emperor, vassals and standard instances. I will try to make a list, but i suggest you to start over from an official quickstart.

dghant1024 commented 10 years ago

Thanks unbit,

I have taken all your suggestions and cleaned the command that I was using along with editing the files to make appropriate corrections. The most important bullet, which was also the cause of most of my dismay, was what you mentioned about "binding the Emperor to an http address requires that address to be configured to route requests to some vassal." It seems that I have misunderstood the instructions here. Listed below is the adjusted command that I execute after reading your response:

/var/www/testbed/env/bin/uwsgi --ini /etc/uwsgi/emperor.ini --http 127.0.0.1:8000

Which still doesn't work. But the command that does work is below:

/var/www/testbed/env/bin/uwsgi --ini /etc/uwsgi/vassals/auth.ini --http 127.0.0.1:8000

What confuses me is that when I run the command directly using the 'auth.ini' file (listed above) everything works. The url (http://127.0.0.1:8000/testbed/auth/admin) is active and available. Though I have read many, many, parts of the the documentation over, and over, again I seem to be misinterpreting what I'm reading; leading me into an abyss-of-ignorance. This leads me to my next question. Is it possible to run uwsgi in 'Emperor' mode without configuring nginx? In my ignorant state I assume that what you mean by "binding the Emperor to an http address" is to use nginx (lighthttp, apache, cherokee, etc) as a proxy !?!? Thanks for your insight thus-far.

unbit commented 10 years ago

yes you can bind an http router/proxy from the Emperor (without the need of nginx or other webservers), but you need to configure it to route requests to vassals using some rule. The Emperor is used to spawn multiple uWSGI instances, so its http router must know to which of them the request must be passed. Generally you use the domain name as the key (something like domain example.com goes to socket :4040). Here you find the options of the http router: http://uwsgi-docs.readthedocs.org/en/latest/Options.html#plugin-http. The most powerful way is the subscription system: http://uwsgi-docs.readthedocs.org/en/latest/SubscriptionServer.html

The docs refer to the fastrouter, but the options are the same just rename --fastrouter-subscription-server to http-subscription-server and your http router will start accepting subscriptions from vassals.

Finally, if you plan to host a single app, do not use the Emperor, it makes no sense.

dghant1024 commented 10 years ago

Thanks ubbit,

I plan on using this configuration for every Django web application I develop under (/var/www/testbed). This will enable me to develop/test multiple applications without restarting/reloading services etc. Your guidance was instrumental in assisting me because I'm not able to run a "configtest" to fault-check my configurations like I'm able to do for an Apache web server (httpd.conf). Also, this link enabled me to sell-the-deal to configure the emperor vessel(s) appropriately -- apparently, Roberto seems to be really sharp and good at was he does. I have listed my working configuration below:

emperor.ini

[uwsgi] shared-socket = 127.0.0.1:3031 http-subscription-server = 127.0.0.1:2626

fastrouter-subscription-server = 127.0.0.1:2626

fastrouter = =0

fastrouter-cheap = true

master = true emperor = /etc/uwsgi/vassals logto = /tmp/uwsgi.log

auth.ini

[uwsgi] subscribe2 = server=127.0.0.1:2626,key=localhost:8888 chdir =/var/www/testbed/project/auth module = auth.wsgi:application home =/var/www/testbed/env virtualenv =/var/www/testbed/env enable-threads = true pythonpath = /var/www/testbed/project/auth processes = 1 socket = 127.0.0.1:0 vacuum = true

Command execution:

/var/www/testbed/env/bin/uwsgi --ini emperor.ini --http :8888