diff --git a/ara/wsgi_sqlite.py b/ara/wsgi_sqlite.py index a65d900a..b58a6ee4 100644 --- a/ara/wsgi_sqlite.py +++ b/ara/wsgi_sqlite.py @@ -51,22 +51,6 @@ import shutil import six import time -if (int(os.getenv('ARA_WSGI_USE_VIRTUALENV', 0)) == 1 and - os.getenv('ARA_WSGI_VIRTUALENV_PATH')): - # Backwards compatibility, we did not always suffix activate_this.py - activate_this = os.getenv('ARA_WSGI_VIRTUALENV_PATH') - if 'activate_this.py' not in activate_this: - activate_this = os.path.join(activate_this, 'bin/activate_this.py') - - if six.PY2: - execfile(activate_this, dict(__file__=activate_this)) # nosec - else: - exec(open(activate_this).read()) # nosec - -TMPDIR_MAX_AGE = int(os.getenv('ARA_WSGI_TMPDIR_MAX_AGE', 3600)) -LOG_ROOT = os.getenv('ARA_WSGI_LOG_ROOT', '/srv/static/logs') -DATABASE_DIRECTORY = os.getenv('ARA_WSGI_DATABASE_DIRECTORY', 'ara-report') - logger = logging.getLogger('ara.wsgi_sqlite') if not logger.handlers: logging.basicConfig(format='%(name)s:%(levelname)s:%(message)s') @@ -86,6 +70,26 @@ def bad_request(environ, start_response, message): def application(environ, start_response): + # Apache SetEnv variables are passed only in environ variable + if (int(environ.get('ARA_WSGI_USE_VIRTUALENV', 0)) == 1 and + environ.get('ARA_WSGI_VIRTUALENV_PATH')): + # Backwards compatibility, we did not always suffix activate_this.py + activate_this = environ.get('ARA_WSGI_VIRTUALENV_PATH') + if 'activate_this.py' not in activate_this: + activate_this = os.path.join(activate_this, 'bin/activate_this.py') + + if six.PY2: + execfile(activate_this, dict(__file__=activate_this)) # nosec + else: + exec(open(activate_this).read()) # nosec + + TMPDIR_MAX_AGE = int(environ.get('ARA_WSGI_TMPDIR_MAX_AGE', 3600)) + LOG_ROOT = environ.get('ARA_WSGI_LOG_ROOT', '/srv/static/logs') + DATABASE_DIRECTORY = environ.get( + 'ARA_WSGI_DATABASE_DIRECTORY', + 'ara-report' + ) + request = environ['REQUEST_URI'] match = re.search('/(?P.*/{}/)'.format(DATABASE_DIRECTORY), request) if not match: diff --git a/doc/source/advanced.rst b/doc/source/advanced.rst index 4abdbb61..bdb6142c 100644 --- a/doc/source/advanced.rst +++ b/doc/source/advanced.rst @@ -110,15 +110,55 @@ middleware. In order to do so, the vhost must look like the following:: LogLevel warn CustomLog /var/log/httpd/logs.domain.tld-access.log combined + # Look out for the user/group which is different based on your distro + WSGIDaemonProcess ara user=apache group=apache processes=4 threads=1 + SetEnv ARA_WSGI_TMPDIR_MAX_AGE 3600 SetEnv ARA_WSGI_LOG_ROOT /srv/static/logs SetEnv ARA_WSGI_DATABASE_DIRECTORY ara-report - WSGIDaemonProcess ara user=apache group=apache processes=4 threads=1 - WSGIScriptAliasMatch ^.*/ara-report /var/www/cgi-bin/ara-wsgi-sqlite + + + + Require all granted + + + + # Redirect everything after /ara-report to the middleware + WSGIScriptAliasMatch ^.*/ara-report /usr/bin/ara-wsgi-sqlite -You'll notice the ``WSGIScriptAliasMatch`` directive pointing to the WSGI -script. This is bundled when installing ARA and can be copied to the location -of your choice by doing:: +Using a virtual environment +--------------------------- - cp -p $(which ara-wsgi-sqlite) /var/www/cgi-bin/ +When using ARA from a virtual environment, you need to adjust your configuration +accordingly. + +For example, your vhost might need to look like this instead:: + + + # Remember that DocumentRoot and ARA_WSGI_LOG_ROOT must match + DocumentRoot /srv/static/logs + ServerName logs.domain.tld + + ErrorLog /var/log/httpd/logs.domain.tld-error.log + LogLevel warn + CustomLog /var/log/httpd/logs.domain.tld-access.log combined + + # Look out for the user/group which is different based on your distro + WSGIDaemonProcess ara user=apache group=apache processes=4 threads=1 python-home=/opt/venv/ara + + SetEnv ARA_WSGI_USE_VIRTUALENV 1 + SetEnv ARA_WSGI_VIRTUALENV_PATH /opt/venv/ara + SetEnv ARA_WSGI_TMPDIR_MAX_AGE 3600 + SetEnv ARA_WSGI_LOG_ROOT /srv/static/logs + SetEnv ARA_WSGI_DATABASE_DIRECTORY ara-report + + + + Require all granted + + + + # Redirect everything after /ara-report to the middleware + WSGIScriptAliasMatch ^.*/ara-report /opt/venv/ara/bin/ara-wsgi-sqlite +