Merge lp:~muffinresearch/graphite/mod_wsgi_example into lp:~graphite-dev/graphite/main

Proposed by Stuart Colville
Status: Merged
Merge reported by: chrismd
Merged at revision: not available
Proposed branch: lp:~muffinresearch/graphite/mod_wsgi_example
Merge into: lp:~graphite-dev/graphite/main
Diff against target: 178 lines (+100/-11)
5 files modified
INSTALL (+33/-8)
README (+1/-1)
check-dependencies.py (+13/-2)
examples/example-graphite-mod-wsgi-vhost.conf (+34/-0)
webapp/graphite/graphite.wsgi (+19/-0)
To merge this branch: bzr merge lp:~muffinresearch/graphite/mod_wsgi_example
Reviewer Review Type Date Requested Status
chrismd Approve
Review via email: mp+27651@code.launchpad.net

Description of the change

This branch provides a basic example for running graphite under mod_wsgi along with updated docs.

The rationale behind this is that mod_python is not currently actively developed [1] and mod_wsgi is the recommended approach for using django in production with Apache. [2]

The branch retains the mod_python examples and instructions to be backwards compatible for existing users though I've written the docs adding a gentle emphasis that mod_wsgi is recommended.

[1] http://blog.dscpl.com.au/2010/05/modpython-project-soon-to-be-officially.html
[2] http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/

To post a comment you must log in.
Revision history for this message
chrismd (chrismd) wrote :

Sorry it took me so long to get around to looking at this. Some of this is already in trunk (the example vhost config) but merging in the INSTALL doc update, etc

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'INSTALL'
2--- INSTALL 2010-03-25 15:01:48 +0000
3+++ INSTALL 2010-06-15 18:55:42 +0000
4@@ -18,7 +18,7 @@
5 pycairo (with PNG backend support)
6 django
7 json (standard in python2.6) or simplejson
8- mod_python (optional - but highly recommended)
9+ mod_wsgi (optional, recommended) or mod_python (optional)
10 python-ldap (optional - needed for ldap-based webapp authentication)
11 python-memcached (optional - needed for webapp caching, big performance boost)
12 python-sqlite2 (optional - a django-supported database module is required)
13@@ -67,13 +67,37 @@
14
15 Apache Configuration
16 -------------------------------------------------------------------------------
17-First off, Apache has to have mod_python configured, this is usually done
18-by including a line like the following in your httpd.conf:
19+When using apache there are two modules available to provide support for python
20+web application.
21+
22+Graphite currently provides example configurations for both of these modules.
23+Of the two mod_wsgi is the most up to date and actively maintained so it's
24+highly recommended if you are starting afresh.
25+
26+ Apache Configuration for Mod_wsgi (recommended)
27+-------------------------------------------------------------------------------
28+
29+If you are using mod_wsgi, Apache has to have mod_wsgi configured,
30+this is usually done by including a line like the following in your
31+httpd.conf:
32+
33+LoadModule wsgi_module modules/mod_wsgi.so
34+
35+ Apache Configuration for Mod_python
36+-------------------------------------------------------------------------------
37+
38+If you choose to use mod_python, Apache has to have mod_python configured,
39+this is usually done by including a line like the following in your
40+httpd.conf:
41
42 LoadModule python_module modules/mod_python.so
43
44-Second you should configure a vhost for graphite (technically it doesn't have
45-to be a vhost but its good practice). This can be done one of two ways.
46+ General Apache Configuration
47+-------------------------------------------------------------------------------
48+
49+Once you have configured the apache module you are using you should configure
50+a vhost for graphite (technically it doesn't have to be a vhost but its good
51+practice). This can be done one of two ways.
52
53 The first way (highly preferred) is to include independent vhost configs.
54
55@@ -82,10 +106,11 @@
56
57 Then simply drop your graphite vhost conf file into the vhosts.d/ directory
58 (or whatever directory your system uses) and apache is ready. You can use
59-the examples/example-graphite-vhost.conf file included in this package as a
60-starting point.
61+either of the example vhost confs as a starting point (See the examples
62+directory of this package and choose the correct one based on whether you
63+are using mod_wsgi or mod_python.)
64
65-The second approach is to copy the contents of the graphite vhost conf file
66+The second approach is to copy the contents of your chosen graphite vhost conf file
67 and insert it down at the end of your httpd.conf.
68
69
70
71=== modified file 'README'
72--- README 2009-09-14 21:40:04 +0000
73+++ README 2010-06-15 18:55:42 +0000
74@@ -2,7 +2,7 @@
75 -------------------------------------------------------------------------------
76 Graphite consists of two major components
77
78- 1) the frontend Django webapp that runs under mod_python Apache
79+ 1) the frontend Django webapp that runs under Apache with mod_python or mod_wsgi
80 2) the backend carbon-cache.py daemon
81
82 Client applications connect to the running carbon-cache.py daemon on port 2003 and send it
83
84=== modified file 'check-dependencies.py'
85--- check-dependencies.py 2010-03-25 15:01:48 +0000
86+++ check-dependencies.py 2010-06-15 18:55:42 +0000
87@@ -69,14 +69,25 @@
88
89
90 # Test for mod_python
91+mod_python_installed = 0
92 try:
93 import mod_python
94+ mod_python_installed = 1
95 except:
96 print "[WARNING] Unable to import the 'mod_python' module, do you have mod_python installed for python %s?" % py_version
97- print "This means you will only be able to run graphite in the development server mode, which is not"
98- print "recommended for production use."
99+ print "This means you will only be able to run graphite under mod_wsgi (if installed)"
100+ print "OR the development server mode, which is not recommended for production use."
101 warning += 1
102
103+# Non-test for mod_wsgi
104+print "[WARNING] Unable to reliably test for the presence of the 'mod_wsgi' module, do you have mod_wsgi installed?"
105+print "Note: mod_wsgi is highly recommended for serving python web applications with Apache"
106+mp_instructions = "mod_python (installed) \nOR " if mod_python_installed else ""
107+print "If mod_wsgi is not installed you will only be able to run graphite "\
108+ "under %sthe development server mode, which is not recommended for production use." % mp_instructions
109+warning += 1
110+
111+
112
113 # Test for python-memcached
114 try:
115
116=== renamed file 'examples/example-graphite-vhost.conf' => 'examples/example-graphite-mod-python-vhost.conf'
117=== added file 'examples/example-graphite-mod-wsgi-vhost.conf'
118--- examples/example-graphite-mod-wsgi-vhost.conf 1970-01-01 00:00:00 +0000
119+++ examples/example-graphite-mod-wsgi-vhost.conf 2010-06-15 18:55:42 +0000
120@@ -0,0 +1,34 @@
121+NameVirtualHost *:80
122+
123+# You may need to manually edit this file to fit your needs.
124+# This configuration assumes the default installation prefix
125+# of /opt/graphite/, if you installed graphite somewhere else
126+# you will need to change all the occurances of /opt/graphite/
127+# in this file to your chosen install location.
128+
129+<VirtualHost *:80>
130+ DocumentRoot "/opt/graphite/webapp"
131+
132+ ErrorLog /opt/graphite/storage/log/webapp/error.log
133+
134+ WSGIDaemonProcess graphite user=www-data group=www-data threads=25
135+ WSGIProcessGroup graphite
136+
137+ WSGIScriptAlias / /opt/graphite/webapp/graphite/graphite.wsgi
138+
139+ <Directory /opt/graphite/webapp>
140+ Order deny,allow
141+ Allow from all
142+ </Directory>
143+
144+ # NOTE: In order for the django admin site media to work you
145+ # must change @DJANGO_ROOT@ to be the path to your django
146+ # installation, which is probably something like:
147+ # /usr/lib/python2.6/site-packages/django
148+ Alias /media/ "@DJANGO_ROOT@/contrib/admin/media/"
149+ <Directory @DJANGO_ROOT@/contrib/admin/media>
150+ Order deny,allow
151+ Allow from all
152+ </Directory>
153+
154+</VirtualHost>
155
156=== added file 'webapp/graphite/graphite.wsgi'
157--- webapp/graphite/graphite.wsgi 1970-01-01 00:00:00 +0000
158+++ webapp/graphite/graphite.wsgi 2010-06-15 18:55:42 +0000
159@@ -0,0 +1,19 @@
160+# You may need to manually edit this file to fit your needs.
161+# This configuration assumes the default installation prefix
162+# of /opt/graphite/, if you installed graphite somewhere else
163+# you will need to change all the occurances of /opt/graphite/
164+# in this file to your chosen install location.
165+
166+import os
167+import sys
168+sys.path.insert(0, '/opt/graphite/webapp/')
169+os.environ['DJANGO_SETTINGS_MODULE'] = 'graphite.settings'
170+
171+import django.core.handlers.wsgi
172+
173+_application = django.core.handlers.wsgi.WSGIHandler()
174+
175+def application(environ, start_response):
176+ environ['PATH_INFO'] = environ['SCRIPT_NAME'] + environ['PATH_INFO']
177+ return _application(environ, start_response)
178+