From 977f065a3f753e19d661ad992a689c684508287e Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Fri, 1 Mar 2019 08:41:07 +1100 Subject: [PATCH] graphite.wsgi : update for django 1.7 Django 1.8 in Xenial hits changes to the app loading made in 1.7 [1]. On Xenail and above, ship a slightly different wsgi loader that uses the new-style loading. [1] https://docs.djangoproject.com/en/dev/releases/1.7/#app-loading-changes Change-Id: Ia741af25391603fe81c0185b586b5841910f714a --- manifests/init.pp | 18 +++++++++++++++++- templates/graphite.wsgi.django17.erb | 15 +++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 templates/graphite.wsgi.django17.erb diff --git a/manifests/init.pp b/manifests/init.pp index c818b40..b252ef1 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -259,9 +259,25 @@ class graphite( require => File['/etc/graphite'], } + # later versions of django require a different wsgi loader; swap it + # in here for > trusty + case $::operatingsystem { + 'Ubuntu': { + if versioncmp($::operatingsystemrelease, '14.04') <= 0 { + $django_wsgi_template = 'graphite.wsgi.erb' + } + else { + $django_wsgi_template = 'graphite.wsgi.django17.erb' + } + } + default: { + fail('Platform not supported') + } + } + file { '/etc/graphite/graphite.wsgi': mode => '0444', - content => template('graphite/graphite.wsgi.erb'), + content => template("graphite/${django_wsgi_template}"), require => File['/etc/graphite'], } diff --git a/templates/graphite.wsgi.django17.erb b/templates/graphite.wsgi.django17.erb new file mode 100644 index 0000000..f46b9fe --- /dev/null +++ b/templates/graphite.wsgi.django17.erb @@ -0,0 +1,15 @@ +import os, sys +sys.path.append('/var/lib/graphite/webapp') +os.environ['DJANGO_SETTINGS_MODULE'] = 'graphite.settings' + +from django.core.wsgi import wsgi_application +application = get_wsgi_application() + +# READ THIS +# Initializing the search index can be very expensive, please include +# the WSGIScriptImport directive pointing to this script in your vhost +# config to ensure the index is preloaded before any requests are handed +# to the process. +from graphite.logger import log +log.info("graphite.wsgi - pid %d - reloading search index" % os.getpid()) +import graphite.metrics.search