From 9a9bf24787e5fe94fec00c68a7204c673d5a5206 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 13 Jan 2013 19:22:27 -0600 Subject: Add current production archweb.wsgi script Signed-off-by: Dan McGee --- archweb.wsgi | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 archweb.wsgi (limited to 'archweb.wsgi') diff --git a/archweb.wsgi b/archweb.wsgi new file mode 100644 index 00000000..2e174249 --- /dev/null +++ b/archweb.wsgi @@ -0,0 +1,15 @@ +#!/usr/bin/python +import os +import sys +import site + +site.addsitedir('/srv/http/archweb-env/lib/python2.7/site-packages') +sys.path.insert(0, "/srv/http") +sys.path.insert(0, "/srv/http/archweb") + +os.environ['DJANGO_SETTINGS_MODULE'] = "archweb.settings" + +os.chdir("/srv/http/archweb") + +import django.core.handlers.wsgi +application = django.core.handlers.wsgi.WSGIHandler() -- cgit v1.2.3-2-g168b From 9234d7787757a712f63d590748897f31d72ac61e Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 13 Jan 2013 19:23:53 -0600 Subject: Simplify the WSGI script Signed-off-by: Dan McGee --- archweb.wsgi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'archweb.wsgi') diff --git a/archweb.wsgi b/archweb.wsgi index 2e174249..abe5419a 100644 --- a/archweb.wsgi +++ b/archweb.wsgi @@ -4,10 +4,9 @@ import sys import site site.addsitedir('/srv/http/archweb-env/lib/python2.7/site-packages') -sys.path.insert(0, "/srv/http") sys.path.insert(0, "/srv/http/archweb") -os.environ['DJANGO_SETTINGS_MODULE'] = "archweb.settings" +os.environ['DJANGO_SETTINGS_MODULE'] = "settings" os.chdir("/srv/http/archweb") -- cgit v1.2.3-2-g168b From c1c12b353851a164777dc7d0fa79d3509f7f0e0e Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 13 Jan 2013 19:31:18 -0600 Subject: Enable newrelic in WSGI if available Signed-off-by: Dan McGee --- archweb.wsgi | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'archweb.wsgi') diff --git a/archweb.wsgi b/archweb.wsgi index abe5419a..6fac21e9 100644 --- a/archweb.wsgi +++ b/archweb.wsgi @@ -3,12 +3,29 @@ import os import sys import site +base_path = "/srv/http/archweb" + site.addsitedir('/srv/http/archweb-env/lib/python2.7/site-packages') -sys.path.insert(0, "/srv/http/archweb") +sys.path.insert(0, base_path) os.environ['DJANGO_SETTINGS_MODULE'] = "settings" -os.chdir("/srv/http/archweb") +os.chdir(base_path) + +using_newrelic = False +try: + import newrelic.agent + from newrelic.api.exceptions import ConfigurationError + try: + newrelic.agent.initialize(os.path.join(base_path, "newrelic.ini")) + using_newrelic = True + except ConfigurationError: + pass +except ImportError: + pass import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() + +if using_newrelic: + application = application = newrelic.agent.wsgi_application()(application) -- cgit v1.2.3-2-g168b From 8986be44be8ed8778e30fc144a2bc76febc11c6d Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 13 Jan 2013 19:56:58 -0600 Subject: More tweaks for New Relic in WSGI script Signed-off-by: Dan McGee --- archweb.wsgi | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'archweb.wsgi') diff --git a/archweb.wsgi b/archweb.wsgi index 6fac21e9..0d1798ab 100644 --- a/archweb.wsgi +++ b/archweb.wsgi @@ -28,4 +28,9 @@ import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() if using_newrelic: - application = application = newrelic.agent.wsgi_application()(application) + _application = application + def application(environ, start_response): + os.environ["NEW_RELIC_LICENSE_KEY"] = environ.get("NEW_RELIC_LICENSE_KEY", None) + return _application(environ, start_response) + + application = newrelic.agent.wsgi_application()(application) -- cgit v1.2.3-2-g168b From 57730e4917e29421adcbe32fa9f6a1aefd4a5c63 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 13 Jan 2013 20:17:16 -0600 Subject: Try 3 at getting the New Relic license key in Signed-off-by: Dan McGee --- archweb.wsgi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'archweb.wsgi') diff --git a/archweb.wsgi b/archweb.wsgi index 0d1798ab..901ac98f 100644 --- a/archweb.wsgi +++ b/archweb.wsgi @@ -17,6 +17,11 @@ try: import newrelic.agent from newrelic.api.exceptions import ConfigurationError try: + key_path = os.path.join(base_path, "newrelic.key") + if os.path.exists(key_path): + with open(key_path) as keyfile: + key = keyfile.read().strip() + os.environ["NEW_RELIC_LICENSE_KEY"] = key newrelic.agent.initialize(os.path.join(base_path, "newrelic.ini")) using_newrelic = True except ConfigurationError: @@ -28,9 +33,4 @@ import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() if using_newrelic: - _application = application - def application(environ, start_response): - os.environ["NEW_RELIC_LICENSE_KEY"] = environ.get("NEW_RELIC_LICENSE_KEY", None) - return _application(environ, start_response) - application = newrelic.agent.wsgi_application()(application) -- cgit v1.2.3-2-g168b From 05f3c5fd199180206dc3c49e967fc9cc18029a8f Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 13 Jan 2013 20:26:11 -0600 Subject: Load key before importing newrelic Their code stupidly grabs the environment variable during import, not during the initialize call. Signed-off-by: Dan McGee --- archweb.wsgi | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'archweb.wsgi') diff --git a/archweb.wsgi b/archweb.wsgi index 901ac98f..f8de2b49 100644 --- a/archweb.wsgi +++ b/archweb.wsgi @@ -14,14 +14,15 @@ os.chdir(base_path) using_newrelic = False try: + key_path = os.path.join(base_path, "newrelic.key") + if os.path.exists(key_path): + with open(key_path) as keyfile: + key = keyfile.read().strip() + os.environ["NEW_RELIC_LICENSE_KEY"] = key + import newrelic.agent from newrelic.api.exceptions import ConfigurationError try: - key_path = os.path.join(base_path, "newrelic.key") - if os.path.exists(key_path): - with open(key_path) as keyfile: - key = keyfile.read().strip() - os.environ["NEW_RELIC_LICENSE_KEY"] = key newrelic.agent.initialize(os.path.join(base_path, "newrelic.ini")) using_newrelic = True except ConfigurationError: -- cgit v1.2.3-2-g168b