Skip to content

Commit

Permalink
installation: fix apache configuration
Browse files Browse the repository at this point in the history
* Creates create "run" directory in instance folder.

* Fixes wrong variable name causing demosite population to fail.

* Adds missing module qrcode to requirements.

* Fixes error output during demosite population.

Co-authored-by: Adrian-Tudor Panescu <[email protected]>

NOTE: beware, patch amended by Tibor to use new file names
  • Loading branch information
jirikuncar committed Jun 4, 2014
1 parent 2f62bdb commit 7fd76fd
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 126 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ include requirements*.txt
recursive-include docs *.xml *.xsl *.xsd *.tpl *.html *.js *.css *.cfg *.bft *.rst *.png *.gif *.ico *.sql
recursive-include invenio *.xml *.xsl *.xsd *.tpl *.html *.js *.kb *.css *.cfg *.bft *.rst *.png *.gif *.ico *.sql

include invenio/invenio.wsgi
include invenio/base/static/img/test*
include invenio/legacy/elmsubmit/mime.types.edited
76 changes: 0 additions & 76 deletions invenio.wsgi

This file was deleted.

55 changes: 51 additions & 4 deletions invenio/base/factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
## This file is part of Invenio.
## Copyright (C) 2011, 2012, 2013 CERN.
## Copyright (C) 2011, 2012, 2013, 2014 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -31,9 +31,8 @@
from .helpers import with_app_context, unicodifier
from .wrappers import Flask
from invenio.ext.registry import Registry, ExtensionRegistry, \
PackageRegistry, ConfigurationRegistry, AutoDiscoverRegistry, \
PackageRegistry, ConfigurationRegistry, \
ImportPathRegistry, BlueprintAutoDiscoveryRegistry
from flask import Blueprint


__all__ = ['create_app', 'with_app_context']
Expand Down Expand Up @@ -84,7 +83,7 @@ def register_secret_key(app):

def create_app(instance_path=None, **kwargs_config):
"""
Prepare WSGI Invenio application based on Flask.
Prepare Invenio application based on Flask.
Invenio consists of a new Flask application with legacy support for
the old WSGI legacy application and the old Python legacy
Expand Down Expand Up @@ -172,3 +171,51 @@ def create_app(instance_path=None, **kwargs_config):
register_legacy_blueprints(app)

return app


def create_wsgi_app(*args, **kwargs):
"""
"""
# wrap warnings (usually from sql queries) to log the traceback
# of their origin for debugging
try:
from invenio.ext.logging import wrap_warn
wrap_warn()
except:
pass

app = create_app(*args, **kwargs)

## Start remote debugger if appropriate:
if app.config.get('CFG_REMOTE_DEBUGGER_ENABLED'):
try:
from invenio.utils import remote_debugger
remote_debugger.start_file_changes_monitor()
if app.config.get('CFG_REMOTE_DEBUGGER_WSGI_LOADING'):
remote_debugger.start()
except Exception as e:
app.logger.error('Remote debugger is not working', e)

@app.before_first_request
def pre_load():
"""
Pre-load citation dictionaries upon WSGI application start-up (the
citation dictionaries are loaded lazily, which is good for CLI
processes such as bibsched, but for web user queries we want them to
be available right after web server start-up)
"""
#FIXME: move to invenio.modules.ranker.views when its created
try:
from invenio.legacy.bibrank.citation_searcher import \
get_citedby_hitset, \
get_refersto_hitset
get_citedby_hitset(None)
get_refersto_hitset(None)
except:
pass

if 'werkzeug-debugger' in app.config.get('CFG_DEVEL_TOOLS', []):
from werkzeug.debug import DebuggedApplication
app = DebuggedApplication(app, evalex=True)

return app
33 changes: 23 additions & 10 deletions invenio/base/scripts/apache.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@ def version(separator='\n'):
return separator.join(out)


@manager.option('-f', '--force', dest='force')
@manager.option('--no-ssl', dest='no_ssl')
@manager.option('-f', '--force', dest='force', action='store_true')
@manager.option('--no-ssl', dest='no_ssl', action='store_true')
@change_command_name
def create_config(force=False, no_ssl=True):
def create_config(force=False, no_ssl=False):
"""
Create Apache configuration files for this site, keeping previous
files in a backup copy.
"""
import os
import pwd
import pkg_resources
import sys
import shutil
from flask import current_app
Expand Down Expand Up @@ -105,13 +106,25 @@ def get_context():
if vhost_site_url_port != '80' or vhost_site_secure_url_port != '443':
listen_directive_needed = True

static_root = current_app.config['COLLECT_STATIC_ROOT']
if not os.path.exists(static_root):
os.mkdir(static_root)

def prepare_alias(filename):
if os.path.isdir(os.path.join(static_root, filename)):
return '/%s/' % (filename, )
return '/%s' % (filename, )

aliases = map(prepare_alias, os.listdir(static_root))

apc1 = {'vhost_site_url_port': vhost_site_url_port,
'servername': vhost_site_url,
'serveralias': vhost_site_url.split('.')[0],
'vhost_ip_address': vhost_ip_address_needed and
_detect_ip_address() or '*',
'wsgi_socket_directive_needed': wsgi_socket_directive_needed,
'listen_directive_needed': listen_directive_needed,
'aliases': aliases,
}

apc2 = {'vhost_site_url_port': vhost_site_secure_url_port,
Expand All @@ -130,16 +143,18 @@ def get_context():
'#SSLCertificateKeyFile %s' % ssl_key_path or
'SSLCertificateKeyFile %s' % ssl_key_path,
'listen_directive_needed': listen_directive_needed,
'aliases': aliases,
}

return [apc1, apc2]

current_app.config.update(
CFG_RUNNING_AS_USER=pwd.getpwuid(os.getuid())[0],
CFG_EXTERNAL_AUTH_USING_SSO=CFG_EXTERNAL_AUTH_USING_SSO,
CFG_WSGIDIR=os.path.join(CFG_PREFIX, 'var', 'www-wsgi'))
CFG_WSGIDIR=os.path.abspath(
pkg_resources.resource_filename('invenio', '')))

apache_conf_dir = current_app.config.get('CFG_ETCDIR') + os.sep + 'apache'
apache_conf_dir = current_app.instance_path + os.sep + 'apache'

print ">>> Going to create Apache conf files..."
conf_files = ['invenio-apache-vhost.conf', 'invenio-apache-vhost-ssl.conf']
Expand Down Expand Up @@ -174,12 +189,10 @@ def get_context():
%s
%s
Please see the INSTALL file for more details.
""" % tuple(map(lambda x: "Include " + apache_conf_dir.encode('utf-8') + os.sep + x,
list(conf_files))))
""" % '\n\n'.join(tuple(map(
lambda x: "Include " + apache_conf_dir.encode('utf-8') + os.sep + x,
list(conf_files[:1 if no_ssl else 2])))))
print ">>> Apache conf files created."


Expand Down
24 changes: 6 additions & 18 deletions invenio/base/templates/invenio-apache-vhost.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ WSGIRestrictStdout Off
ServerAdmin {{ config.CFG_SITE_ADMIN_EMAIL }}
{%- endblock server -%}
{%- block directory_web %}
DocumentRoot {{ config.CFG_WEBDIR }}
<Directory {{ config.CFG_WEBDIR }}>
DocumentRoot {{ config.COLLECT_STATIC_ROOT }}
<Directory {{ config.COLLECT_STATIC_ROOT }}>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Expand All @@ -78,23 +78,11 @@ WSGIRestrictStdout Off
{%- endblock logging -%}
{%- block aliases %}
DirectoryIndex index.en.html index.html
Alias /static/ {{ config.CFG_WEBDIR }}/static/
Alias /img/ {{ config.CFG_WEBDIR }}/img/
Alias /css/ {{ config.CFG_WEBDIR }}/css/
Alias /js/ {{ config.CFG_WEBDIR }}/js/
Alias /flash/ {{ config.CFG_WEBDIR }}/flash/
Alias /export/ {{ config.CFG_WEBDIR }}/export/
Alias /MathJax/ {{ config.CFG_WEBDIR }}/MathJax/
Alias /jsCalendar/ {{ config.CFG_WEBDIR }}/jsCalendar/
Alias /ckeditor/ {{ config.CFG_WEBDIR }}/ckeditor/
Alias /mediaelement/ {{ config.CFG_WEBDIR }}/mediaelement/
# Auto-generated aliasses
{% for alias in aliases -%}
Alias {{ alias }} {{ config.COLLECT_STATIC_ROOT+alias }}
{% endfor %}
AliasMatch /sitemap-(.*) {{ config.CFG_WEBDIR }}/sitemap-$1
Alias /robots.txt {{ config.CFG_WEBDIR }}/robots.txt
Alias /favicon.ico {{ config.CFG_WEBDIR }}/favicon.ico
Alias /apple-touch-icon-144-precomposed.png {{ config.CFG_WEBDIR }}/apple-touch-icon-144-precomposed.png
Alias /apple-touch-icon-114-precomposed.png {{ config.CFG_WEBDIR }}/apple-touch-icon-114-precomposed.png
Alias /apple-touch-icon-72-precomposed.png {{ config.CFG_WEBDIR }}/apple-touch-icon-72-precomposed.png
Alias /apple-touch-icon-57-precomposed.png {{ config.CFG_WEBDIR }}/apple-touch-icon-57-precomposed.png
{%- endblock aliases -%}
{%- block wsgi %}
WSGIScriptAlias / {{ config.CFG_WSGIDIR }}/invenio.wsgi
Expand Down
20 changes: 9 additions & 11 deletions invenio/ext/logging/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,17 +502,15 @@ def wrap_warn():

def wrapper(showwarning):
@wraps(showwarning)
def new_showwarning(message=None, category=None, filename=None, lineno=None, file=None, line=None):
invenio_err = open(os.path.join(cfg['CFG_LOGDIR'], 'invenio.err'), "a")
print >> invenio_err, "* %(time)s -> WARNING: %(category)s: %(message)s (%(file)s:%(line)s)\n" % {
'time': time.strftime("%Y-%m-%d %H:%M:%S"),
'category': category,
'message': message,
'file': filename,
'line': lineno}
print >> invenio_err, "** Traceback details\n"
traceback.print_stack(file=invenio_err)
print >> invenio_err, "\n"
def new_showwarning(message=None, category=None, filename=None,
lineno=None, file=None, line=None):
current_app.logger.warning("* %(time)s -> WARNING: %(category)s: %(message)s (%(file)s:%(line)s)\n" % {
'time': time.strftime("%Y-%m-%d %H:%M:%S"),
'category': category,
'message': message,
'file': filename,
'line': lineno} + "** Traceback details\n" +
str(traceback.format_stack()) + "\n")
return new_showwarning

warnings.showwarning = wrapper(warnings.showwarning)
6 changes: 3 additions & 3 deletions invenio/ext/sqlalchemy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def process_bind_param(self, value, dialect):
return value

def process_result_value(self, value, dialect):
if value is not None:
value = json.loads(value)
return value
if value:
return json.loads(value)
return None


class MarshalBinary(TypeDecorator):
Expand Down
29 changes: 29 additions & 0 deletions invenio/invenio.wsgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
## This file is part of Invenio.
## Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

"""
mod_wsgi Invenio application loader.
"""

## You can't write to stdout in mod_wsgi, but some of our
## dependecies do this! (e.g. 4Suite)
import sys
sys.stdout = sys.stderr

from invenio.base.factory import create_wsgi_app
application = create_wsgi_app()
8 changes: 6 additions & 2 deletions invenio/legacy/bibsched/bibtask.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@
import logging.handlers
import random

from flask import current_app
from socket import gethostname

from invenio.legacy.dbquery import run_sql, _db_login
from invenio.modules.access.engine import acc_authorize_action
from invenio.config import CFG_PREFIX, CFG_BINDIR, CFG_LOGDIR, \
from invenio.config import CFG_BINDIR, CFG_LOGDIR, \
CFG_BIBSCHED_PROCESS_USER, CFG_TMPDIR, CFG_SITE_SUPPORT_EMAIL
from invenio.ext.logging import register_exception

Expand Down Expand Up @@ -923,7 +924,10 @@ def _task_run(task_run_fnc):
## We prepare the pid file inside /prefix/var/run/taskname_id.pid
check_running_process_user()
try:
pidfile_name = os.path.join(CFG_PREFIX, 'var', 'run',
CFG_BIBTASK_RUN_DIR = os.path.join(current_app.instance_path, 'run')
if not os.path.exists(CFG_BIBTASK_RUN_DIR):
os.mkdir(CFG_BIBTASK_RUN_DIR)
pidfile_name = os.path.join(CFG_BIBTASK_RUN_DIR,
'bibsched_task_%d.pid' % _TASK_PARAMS['task_id'])
pidfile = open(pidfile_name, 'w')
pidfile.write(str(os.getpid()))
Expand Down
Loading

0 comments on commit 7fd76fd

Please sign in to comment.