Skip to content

Commit

Permalink
frontend: Replaces mod_python by mod_wsgi apache module
Browse files Browse the repository at this point in the history
This patch also repairs bug with readonly_connection to
mysql database.

Signed-off-by: Jiří Župka <[email protected]>
  • Loading branch information
Jiří Župka authored and lmr committed Jun 8, 2012
1 parent 9bd8fcd commit ee3cced
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
25 changes: 14 additions & 11 deletions apache/conf/django-directives
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ RewriteRule /media/(css|img|js)(.*) /usr/lib/python2.7/site-packages/django/cont
RewriteCond /usr/lib/python2.7/site-packages/django/contrib/admin/static/admin -d
RewriteRule /media/(css|img|js)(.*) /usr/lib/python2.7/site-packages/django/contrib/admin/static/admin/$1/$2

<Location ~ "/(afe|new_tko)/server">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE frontend.settings
PythonDebug On
# Force our own site-packages to be loaded by mod_python prior
# to mod_python's system python site-packages directory.
# This way our code can depend on library versions other than
# those available as packages on various OS distributions.
PythonPath "['/usr/local/autotest/site-packages', '/usr/local/autotest', '/usr/lib/python2.7/site-packages/autotest', '/usr/lib/python2.6/site-packages/autotest', '/usr/lib/python2.5/site-packages/autotest', '/usr/lib/python2.4/site-packages/autotest'] + sys.path"
</Location>
# Configuration for mod_wsgi
RewriteRule ^/(afe|new_tko)/server(.*)$ /$1/server$2 [QSA,PT,L]

WSGISocketPrefix run/wsgi

WSGIDaemonProcess apache processes=10 threads=1
WSGIProcessGroup apache

WSGIScriptAliasMatch /(afe|new_tko)/server.* /usr/local/autotest/frontend/frontend.wsgi

<Directory /usr/local/autotest/frontend/>
Order allow,deny
Allow from all
</Directory>
11 changes: 11 additions & 0 deletions frontend/db/backends/afe/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ def __init__(self, *args, **kwargs):
except TypeError:
self.ops = DatabaseOperations(connection=kwargs.get('connection'))
self.introspection = MySQLIntrospection(self)

def _valid_connection(self):
if self.connection is not None:
if self.connection.open:
try:
self.connection.ping()
return True
except DatabaseError:
self.connection.close()
self.connection = None
return False
22 changes: 22 additions & 0 deletions frontend/frontend.wsgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os, sys

path_list = ['/usr/local/autotest/site-packages', '/usr/local/autotest',
'/usr/lib/python2.7/site-packages/autotest',
'/usr/lib/python2.6/site-packages/autotest',
'/usr/lib/python2.5/site-packages/autotest',
'/usr/lib/python2.4/site-packages/autotest']

for p in path_list:
if os.path.isdir(p):
sys.path.append(p)

os.environ['DJANGO_SETTINGS_MODULE'] = 'frontend.settings'

import django.core.handlers.wsgi

_application = django.core.handlers.wsgi.WSGIHandler()

def application(environ, start_response):
environ['DJANGO_USE_POST_REWRITE'] = "yes"
environ['PATH_INFO'] = environ['SCRIPT_NAME'] + environ['PATH_INFO']
return _application(environ, start_response)

0 comments on commit ee3cced

Please sign in to comment.