<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Fighting Rabbits &#187; Random</title>
	<atom:link href="http://fightingrabbits.com/archives/category/random/feed" rel="self" type="application/rss+xml" />
	<link>http://fightingrabbits.com</link>
	<description>and herding cats...</description>
	<lastBuildDate>Wed, 23 Jun 2010 12:28:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Nginx &amp; Django on Webfaction &#8211; Part 3</title>
		<link>http://fightingrabbits.com/archives/210</link>
		<comments>http://fightingrabbits.com/archives/210#comments</comments>
		<pubDate>Fri, 30 Oct 2009 16:52:11 +0000</pubDate>
		<dc:creator>Richard Cooper</dc:creator>
				<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://fightingrabbits.com/?p=210</guid>
		<description><![CDATA[Now that we have a stable and resilient environment (See Part 1a, Part 1b, and Part 2) I&#8217;m going to show you how we can hand off some of the work of file uploads to nginx and even get a nice upload progress bar into the bargain :) Take a deep breath as this is [...]]]></description>
			<content:encoded><![CDATA[<p>Now that we have a stable and resilient environment (See Part 1a, Part 1b, and Part 2) I&#8217;m going to show you how we can hand off some of the work of file uploads to nginx and even get a nice upload progress bar into the bargain :)<br />
Take a deep breath as this is quite a long one&#8230;. :)<br />
<span id="more-210"></span><br />
First of all we will need to configure our django application, and add some models and views to handle the uploads (I&#8217;ve given some basic examples below but you will want to roll your own!).<br />
(I&#8217;m assuming you already have a suitable project and app outline setup!)</p>
<p>models.py:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">datetime</span>
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">db</span> <span style="color: #ff7700;font-weight:bold;">import</span> models
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Upload<span style="color: black;">&#40;</span>models.<span style="color: black;">Model</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;Uploaded files.&quot;&quot;&quot;</span>
    <span style="color: #008000;">file</span> = models.<span style="color: black;">FileField</span><span style="color: black;">&#40;</span>upload_to=<span style="color: #483d8b;">'uploads'</span>,<span style="color: black;">&#41;</span>
    timestamp = models.<span style="color: black;">DateTimeField</span><span style="color: black;">&#40;</span>default=<span style="color: #dc143c;">datetime</span>.<span style="color: #dc143c;">datetime</span>.<span style="color: black;">now</span><span style="color: black;">&#41;</span>
    notes = models.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>max_length=<span style="color: #ff4500;">255</span>, blank=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">class</span> Meta:
        ordering = <span style="color: black;">&#91;</span><span style="color: #483d8b;">'-timestamp'</span>,<span style="color: black;">&#93;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__unicode__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> u<span style="color: #483d8b;">&quot;%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: #008000;">file</span><span style="color: black;">&#41;</span>
&nbsp;
    @<span style="color: #008000;">property</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> size<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> filesizeformat<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: #008000;">file</span>.<span style="color: black;">size</span><span style="color: black;">&#41;</span></pre></div></div>

<p>forms.py:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django <span style="color: #ff7700;font-weight:bold;">import</span> forms
<span style="color: #ff7700;font-weight:bold;">from</span> models <span style="color: #ff7700;font-weight:bold;">import</span> Upload
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> UploadForm<span style="color: black;">&#40;</span>forms.<span style="color: black;">models</span>.<span style="color: black;">ModelForm</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">class</span> Meta:
        model = Upload
        exclude = <span style="color: black;">&#40;</span><span style="color: #483d8b;">'timestamp'</span>,<span style="color: black;">&#41;</span></pre></div></div>

<p>views.py:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> forms <span style="color: #ff7700;font-weight:bold;">import</span> UploadForm
<span style="color: #ff7700;font-weight:bold;">from</span> models <span style="color: #ff7700;font-weight:bold;">import</span> Upload
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">datetime</span>
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">forms</span> <span style="color: #ff7700;font-weight:bold;">import</span> save_instance
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">shortcuts</span> <span style="color: #ff7700;font-weight:bold;">import</span> render_to_response
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">template</span> <span style="color: #ff7700;font-weight:bold;">import</span> RequestContext
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">http</span> <span style="color: #ff7700;font-weight:bold;">import</span> HttpResponseRedirect
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">core</span>.<span style="color: black;">urlresolvers</span> <span style="color: #ff7700;font-weight:bold;">import</span> reverse
&nbsp;
<span style="color: #808080; font-style: italic;">#Our initial page</span>
<span style="color: #ff7700;font-weight:bold;">def</span> initial<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>:
	data = <span style="color: black;">&#123;</span>
		<span style="color: #483d8b;">'form'</span>: UploadForm<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>,
	<span style="color: black;">&#125;</span>
	<span style="color: #ff7700;font-weight:bold;">return</span> render_to_response<span style="color: black;">&#40;</span><span style="color: #483d8b;">'upload.html'</span>, data, RequestContext<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;">#Our file upload handler that the form will post to</span>
<span style="color: #ff7700;font-weight:bold;">def</span> upload<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> request.<span style="color: black;">method</span> == <span style="color: #483d8b;">'POST'</span>:
        form = UploadForm<span style="color: black;">&#40;</span>request.<span style="color: black;">POST</span>, request.<span style="color: black;">FILES</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> form.<span style="color: black;">is_valid</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
            upload = Upload<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            upload.<span style="color: black;">timestamp</span> = <span style="color: #dc143c;">datetime</span>.<span style="color: #dc143c;">datetime</span>.<span style="color: black;">now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            save_instance<span style="color: black;">&#40;</span>form, upload<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">return</span> HttpResponseRedirect<span style="color: black;">&#40;</span>reverse<span style="color: black;">&#40;</span><span style="color: #483d8b;">'initial'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>urls.py:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">conf</span>.<span style="color: black;">urls</span>.<span style="color: black;">defaults</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">conf</span> <span style="color: #ff7700;font-weight:bold;">import</span> settings
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span> <span style="color: #ff7700;font-weight:bold;">import</span> admin
admin.<span style="color: black;">autodiscover</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
urlpatterns = patterns<span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span>,
    <span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^admin/'</span>, include<span style="color: black;">&#40;</span>admin.<span style="color: #dc143c;">site</span>.<span style="color: black;">urls</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>,
    <span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^media/(?P&lt;path&gt;.*)$'</span>, <span style="color: #483d8b;">'django.views.static.serve'</span>, <span style="color: black;">&#123;</span><span style="color: #483d8b;">'document_root'</span>: settings.<span style="color: black;">MEDIA_ROOT</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#41;</span>
&nbsp;
urlpatterns += patterns<span style="color: black;">&#40;</span><span style="color: #483d8b;">'app.views'</span>,
    url<span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^$'</span>,<span style="color: #483d8b;">'initial'</span>, name=<span style="color: #483d8b;">'initial'</span><span style="color: black;">&#41;</span>,
    url<span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^upload/$'</span>,<span style="color: #483d8b;">'upload'</span>, name=<span style="color: #483d8b;">&quot;upload&quot;</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#41;</span></pre></div></div>

<p>Next we&#8217;ll add a couple of templates to display our upload form.<br />
base.html:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=utf-8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Upload Test<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;{{MEDIA_URL|default:&quot;</span><span style="color: #66cc66;">/</span><span style="color: #000066;">media</span><span style="color: #66cc66;">/</span><span style="color: #ff0000;">&quot;}}css/screen.css&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
    {% block main %}{% endblock %}
    {% block js %}{% endblock %}
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>upload.html:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">{% extends &quot;base.html&quot; %}
{% block main %}
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;upload_form&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;{% url upload %}&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">enctype</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;multipart/form-data&quot;</span> <span style="color: #000066;">accept-charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;steps&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>Upload a new file<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;step&quot;</span>&gt;</span>1:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>{{form.file}}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
    {% if form.file.errors %}<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>{{form.file.errors}}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>{% endif %}
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;step&quot;</span>&gt;</span>2:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>{{form.notes}}<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;instruction&quot;</span>&gt;</span> Add a note...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
    {% if form.file.errors %}<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>{{form.notes.errors}}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>{% endif %}
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;step&quot;</span>&gt;</span>3:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Upload&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
{% endblock %}</pre></div></div>

<p>OK now we have a working uploader with the advantage that our nginx server will cache the file until it is fully uploaded and then pass the uploaded file to our django instance locally. What happens if we are sending large files that may take some time to upload? (e.g. mp3 or video) &#8211; we need some feedback to show that the upload is progressing.</p>
<p>Let&#8217;s add some code to our nginx.conf file to use the <a href="http://wiki.nginx.org/NginxHttpUploadProgressModule">upload progress module</a> we compiled in part 1a. This module will track the total uploaded bytes for the upload and allow us to query the status and progress.</p>
<p>First we need to set up an upload &#8220;zone&#8221; and reserve some server memory for tracking uploads by using the following directive in the http section of our nginx.conf:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">upload_progress <span style="color: #000000; font-weight: bold;">&lt;</span>zone_name<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>memory<span style="color: #000000; font-weight: bold;">&gt;</span>;</pre></div></div>

<p>next we need to tell nginx to track uploads to Django under this zone by adding the following directive to our django location:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">track_uploads <span style="color: #000000; font-weight: bold;">&lt;</span>zone_name<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>timeout<span style="color: #000000; font-weight: bold;">&gt;</span>;</pre></div></div>

<p>and finally we need to add a new location to poll for our upload status:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">location ^~ <span style="color: #000000; font-weight: bold;">/</span>upload<span style="color: #000000; font-weight: bold;">/</span>progress <span style="color: #7a0874; font-weight: bold;">&#123;</span>
      report_uploads <span style="color: #000000; font-weight: bold;">&lt;</span>zone_name<span style="color: #000000; font-weight: bold;">&gt;</span>;
    <span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>for a zone called uploadtracker our nginx.conf should now look something like this (Note the client_max_body_size is now set to allow 50Mb uploads!):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">daemon off;
worker_processes <span style="color: #000000;">1</span>;
&nbsp;
events <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    worker_connections <span style="color: #000000;">1024</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
http <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    include             mime.types;
    default_type        application<span style="color: #000000; font-weight: bold;">/</span>octet-stream;	
    upload_progress     uploadtracker 1m;	
&nbsp;
    server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        listen  <span style="color: #000000;">55615</span>;
        server_name <span style="color: #000000; font-weight: bold;">*</span>.mydomain.com;
        client_max_body_size 50m;
&nbsp;
        location ^~ <span style="color: #000000; font-weight: bold;">/</span>upload<span style="color: #000000; font-weight: bold;">/</span>progress <span style="color: #7a0874; font-weight: bold;">&#123;</span>
            report_uploads uploadtracker;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        location <span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
           <span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #000000; font-weight: bold;">/</span>upload<span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        location ~<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>favicon.ico <span style="color: #7a0874; font-weight: bold;">&#123;</span>
           root <span style="color: #000000; font-weight: bold;">/</span>upload<span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>img<span style="color: #000000; font-weight: bold;">/</span>;
           access_log off;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        location <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
            proxy_set_header  	        X-Real-IP  <span style="color: #007800;">$remote_addr</span>;
            proxy_set_header            X-Forwarded-For <span style="color: #007800;">$proxy_add_x_forwarded_for</span>;
            fastcgi_pass                unix:<span style="color: #000000; font-weight: bold;">/</span>upload<span style="color: #000000; font-weight: bold;">/</span>django.sock;
            fastcgi_pass_header         Authorization;          
            fastcgi_hide_header         X-Accel-Redirect;
            fastcgi_hide_header         X-Sendfile;
            fastcgi_intercept_errors    off;
            include                     fastcgi_params;
            track_uploads uploadtracker 30s;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>You&#8217;ll need to restart nginx with ./sbin/nginx -s reload for it to pick up the changes or if you are using supervisor you can use supervisorctl restart all to restart the django and nginx instances.</p>
<p>Now we need to add some java-script (and html) to poll the server and update a progress bar on the client side. I&#8217;ll use MooTools and the excellent dwProgressBar from <a href="http://davidwalsh.name/progress-bar-animated-mootools">david walsh</a> to do the heavy lifting for this although it should be easy to re-write in the framework of your choice.</p>
<p>first lets change the upload.html template and add in some html and some css for the progress bar:<br />
upload.html:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">{% extends &quot;base.html&quot; %}
{% block main %}
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;upload_form&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;{% url upload %}&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">enctype</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;multipart/form-data&quot;</span> <span style="color: #000066;">accept-charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;steps&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>Upload a new file<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;step&quot;</span>&gt;</span>1:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>{{form.file}}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
    {% if form.file.errors %}<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>{{form.file.errors}}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>{% endif %}
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;step&quot;</span>&gt;</span>2:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>{{form.notes}}<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;instruction&quot;</span>&gt;</span> Add a note...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
    {% if form.file.errors %}<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>{{form.notes.errors}}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>{% endif %}
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;step&quot;</span>&gt;</span>3:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Upload&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;progress_container&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;progress_filename&quot;</span>&gt;</span>Please Choose a File...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;put-bar-here&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
{% endblock %}
{% block js %}
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;{{MEDIA_URL|default:&quot;</span><span style="color: #66cc66;">/</span><span style="color: #000066;">media</span><span style="color: #66cc66;">/</span><span style="color: #ff0000;">&quot;}}js/mootools-1.2.4-core.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;{{MEDIA_URL|default:&quot;</span><span style="color: #66cc66;">/</span><span style="color: #000066;">media</span><span style="color: #66cc66;">/</span><span style="color: #ff0000;">&quot;}}js/mootools-1.2.4.1-more.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;{{MEDIA_URL|default:&quot;</span><span style="color: #66cc66;">/</span><span style="color: #000066;">media</span><span style="color: #66cc66;">/</span><span style="color: #ff0000;">&quot;}}js/dwProgressBar.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
{% endblock %}</pre></div></div>

<p>screen.css:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* Progress Bar */</span>
<span style="color: #cc00cc;">#progress_container</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">.9em</span><span style="color: #00AA00;">;</span>width<span style="color: #00AA00;">:</span> <span style="color: #933;">400px</span><span style="color: #00AA00;">;</span>height<span style="color: #00AA00;">:</span> <span style="color: #933;">80px</span><span style="color: #00AA00;">;</span>margin<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>background-<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>padding<span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#box2</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../img/progress-back.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">right</span> <span style="color: #993333;">center</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">400px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">18px</span><span style="color: #00AA00;">;</span>float<span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#perc2</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../img/progress.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">right</span> <span style="color: #993333;">center</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">18px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#text</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #3333ff;">:tahoma</span><span style="color: #00AA00;">,</span> arial<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>font-<span style="color: #000000; font-weight: bold;">size</span><span style="color: #00AA00;">:</span><span style="color: #933;">11px</span><span style="color: #00AA00;">;</span>color<span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>float<span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>padding<span style="color: #00AA00;">:</span><span style="color: #933;">3px</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#progress_filename</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">.9em</span><span style="color: #00AA00;">;</span>width<span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span>line-<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">1.2em</span><span style="color: #00AA00;">;</span>padding<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">10px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>color<span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Now we can add our javascript &#8211; first we will create our progress bar &#8211; add this after the last &lt;script&gt; tag in the upload.html template</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span><span style="color: #339933;">&gt;</span>
pb2 <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> dwProgressBar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    container<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'put-bar-here'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    startPercentage<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
    speed<span style="color: #339933;">:</span><span style="color: #CC0000;">1000</span><span style="color: #339933;">,</span>
    boxID<span style="color: #339933;">:</span> <span style="color: #3366CC;">'box2'</span><span style="color: #339933;">,</span>
    percentageID<span style="color: #339933;">:</span> <span style="color: #3366CC;">'perc2'</span><span style="color: #339933;">,</span>
    displayID<span style="color: #339933;">:</span> <span style="color: #3366CC;">'text'</span><span style="color: #339933;">,</span>
    displayText<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Next we need to create a unique id for our upload:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> uuid <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span>
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">32</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    uuid <span style="color: #339933;">+=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">16</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">16</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The next bit is where it gets a little tricky we are going to use MooTools to create a request to our nginx progress location, we will use Request.Periodical to send a request every second. The nginx server will return a JSON response containing the status of the upload, along with some other data such as total bytes and uploaded bytes depending on the status.<br />
Note: for this to work in WebKit based browsers we need to set async=false on the request due to this bug <a href="https://bugs.webkit.org/show_bug.cgi?id=23933">https://bugs.webkit.org/show_bug.cgi?id=23933</a></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> req <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Request<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    method<span style="color: #339933;">:</span> <span style="color: #3366CC;">'get'</span><span style="color: #339933;">,</span>
    headers<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'X-Progress-ID'</span><span style="color: #339933;">:</span> uuid<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'/upload/progress/'</span><span style="color: #339933;">,</span>
    initialDelay<span style="color: #339933;">:</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span>
    delay<span style="color: #339933;">:</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">,</span>
    limit<span style="color: #339933;">:</span> <span style="color: #CC0000;">10000</span><span style="color: #339933;">,</span>
    async<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
    onSuccess<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>reply<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        test <span style="color: #339933;">=</span> JSON.<span style="color: #660066;">decode</span><span style="color: #009900;">&#40;</span>reply<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>test.<span style="color: #660066;">state</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;uploading&quot;</span><span style="color: #339933;">:</span> 
                percent <span style="color: #339933;">=</span> <span style="color: #CC0000;">0.00</span> <span style="color: #339933;">+</span> parseFloat<span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>test.<span style="color: #660066;">received</span> <span style="color: #339933;">/</span> test.<span style="color: #660066;">size</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'progress_filename'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'html'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Uploading '</span> <span style="color: #339933;">+</span> filename <span style="color: #339933;">+</span> <span style="color: #3366CC;">' ...'</span> <span style="color: #339933;">+</span> percent <span style="color: #339933;">+</span> <span style="color: #3366CC;">'%'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                pb2.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span>percent<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
                <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;starting&quot;</span><span style="color: #339933;">:</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'progress_filename'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'html'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Starting Upload... '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
                <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;error&quot;</span><span style="color: #339933;">:</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'progress_filename'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'html'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Upload Error... '</span> <span style="color: #339933;">+</span> test.<span style="color: #000066;">status</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;done&quot;</span><span style="color: #339933;">:</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'progress_filename'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'html'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Upload Finished...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                req.<span style="color: #660066;">stopTimer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
                console.<span style="color: #660066;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Oooops!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>  
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Finally we hook it all together by adding an onClick handler to the submit button to change the action on our form, get the filename, and start our periodical requests.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'submit'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    filename <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id_file&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'value'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/[\/\\]/</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;progress_filename&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'html'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Uploading '</span> <span style="color: #339933;">+</span> filename <span style="color: #339933;">+</span> <span style="color: #3366CC;">' ...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;upload_form&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'action'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;/upload/?X-Progress-ID=&quot;</span> <span style="color: #339933;">+</span> uuid<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    req.<span style="color: #660066;">startTimer</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'X-Progress-ID='</span> <span style="color: #339933;">+</span> uuid<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The final upload.html template looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">{% extends &quot;base.html&quot; %}
&nbsp;
{% block main %}
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;upload_form&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;{% url upload %}&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">enctype</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;multipart/form-data&quot;</span> <span style="color: #000066;">accept-charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;steps&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>Upload a new file<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;step&quot;</span>&gt;</span>1:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>{{form.file}}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
    {% if form.file.errors %}<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>{{form.file.errors}}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>{% endif %}
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;step&quot;</span>&gt;</span>2:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>{{form.notes}}<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;instruction&quot;</span>&gt;</span> Add a note...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
    {% if form.file.errors %}<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>{{form.notes.errors}}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>{% endif %}
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;step&quot;</span>&gt;</span>3:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Upload&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;progress_container&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;progress_filename&quot;</span>&gt;</span>Please Choose a File...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;put-bar-here&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
{% endblock %}
&nbsp;
{% block js %}
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;{{MEDIA_URL|default:&quot;</span><span style="color: #66cc66;">/</span><span style="color: #000066;">media</span><span style="color: #66cc66;">/</span><span style="color: #ff0000;">&quot;}}js/mootools-1.2.4-core.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;{{MEDIA_URL|default:&quot;</span><span style="color: #66cc66;">/</span><span style="color: #000066;">media</span><span style="color: #66cc66;">/</span><span style="color: #ff0000;">&quot;}}js/mootools-1.2.4.1-more.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;{{MEDIA_URL|default:&quot;</span><span style="color: #66cc66;">/</span><span style="color: #000066;">media</span><span style="color: #66cc66;">/</span><span style="color: #ff0000;">&quot;}}js/dwProgressBar.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;</span>
    var uuid = &quot;&quot;
    pb2 = new dwProgressBar({
        container: $('put-bar-here'),
        startPercentage: 0,
        speed:1000,
        boxID: 'box2',
        percentageID: 'perc2',
        displayID: 'text',
        displayText: false
    });
&nbsp;
    for (i = 0; i <span style="color: #009900;">&lt; <span style="color: #cc66cc;">32</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #009900;">        uuid +<span style="color: #66cc66;">=</span> Math.floor<span style="color: #66cc66;">&#40;</span>Math.random<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> * <span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span>.toString<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">    <span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #009900;">    var req <span style="color: #66cc66;">=</span> new Request<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">method</span>: <span style="color: #ff0000;">'get'</span>,</span>
<span style="color: #009900;">        <span style="color: #000066;">headers</span>: <span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">'X-Progress-ID'</span>: uuid<span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #009900;">        url: <span style="color: #ff0000;">'/upload/progress/'</span>,</span>
<span style="color: #009900;">        initialDelay: <span style="color: #cc66cc;">500</span>,</span>
<span style="color: #009900;">        delay: <span style="color: #cc66cc;">1000</span>,</span>
<span style="color: #009900;">        limit: <span style="color: #cc66cc;">10000</span>,</span>
<span style="color: #009900;">        onSuccess: function<span style="color: #66cc66;">&#40;</span>reply<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #009900;">            test <span style="color: #66cc66;">=</span> JSON.decode<span style="color: #66cc66;">&#40;</span>reply<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">            switch<span style="color: #66cc66;">&#40;</span>test.state<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #009900;">                case <span style="color: #ff0000;">&quot;uploading&quot;</span>: </span>
<span style="color: #009900;">                    percent <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0.00</span> + parseFloat<span style="color: #66cc66;">&#40;</span>Math.floor<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>test.received <span style="color: #66cc66;">/</span> test.<span style="color: #000066;">size</span><span style="color: #66cc66;">&#41;</span>*<span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">                    $<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'progress_filename'</span><span style="color: #66cc66;">&#41;</span>.set<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'html'</span>,<span style="color: #ff0000;">'Uploading '</span> + filename + <span style="color: #ff0000;">' ...'</span> + percent + <span style="color: #ff0000;">'%'</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">                    pb2.set<span style="color: #66cc66;">&#40;</span>percent<span style="color: #66cc66;">&#41;</span>; </span>
<span style="color: #009900;">                    break;</span>
<span style="color: #009900;">                case <span style="color: #ff0000;">&quot;starting&quot;</span>:</span>
<span style="color: #009900;">                    $<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'progress_filename'</span><span style="color: #66cc66;">&#41;</span>.set<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'html'</span>,<span style="color: #ff0000;">'Starting Upload... '</span><span style="color: #66cc66;">&#41;</span>; </span>
<span style="color: #009900;">                    break;</span>
<span style="color: #009900;">                case <span style="color: #ff0000;">&quot;error&quot;</span>:</span>
<span style="color: #009900;">                    $<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'progress_filename'</span><span style="color: #66cc66;">&#41;</span>.set<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'html'</span>,<span style="color: #ff0000;">'Upload Error... '</span> + test.status<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">                    break;</span>
<span style="color: #009900;">                case <span style="color: #ff0000;">&quot;done&quot;</span>:</span>
<span style="color: #009900;">                    $<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'progress_filename'</span><span style="color: #66cc66;">&#41;</span>.set<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'html'</span>,<span style="color: #ff0000;">'Upload Finished...'</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">                    req.stopTimer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">                    break;</span>
<span style="color: #009900;">                default:</span>
<span style="color: #009900;">                    console.debug<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Oooops!&quot;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">                    break;  </span>
<span style="color: #009900;">            <span style="color: #66cc66;">&#125;</span></span>
<span style="color: #009900;">        <span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #009900;">    <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span></span>
&nbsp;
<span style="color: #009900;">    $<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'submit'</span><span style="color: #66cc66;">&#41;</span>.addEvent<span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'click'</span>, function<span style="color: #66cc66;">&#40;</span>evt<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></span>
<span style="color: #009900;">        filename <span style="color: #66cc66;">=</span> $<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;id_file&quot;</span><span style="color: #66cc66;">&#41;</span>.get<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'value'</span><span style="color: #66cc66;">&#41;</span>.split<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">/</span><span style="color: #66cc66;">&#91;</span>\<span style="color: #66cc66;">/</span>\\<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">/</span><span style="color: #66cc66;">&#41;</span>.pop<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">        $<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;progress_filename&quot;</span><span style="color: #66cc66;">&#41;</span>.set<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'html'</span>,<span style="color: #ff0000;">'Uploading '</span> + filename + <span style="color: #ff0000;">' ...'</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">        $<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;upload_form&quot;</span><span style="color: #66cc66;">&#41;</span>.set<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'action'</span>, <span style="color: #ff0000;">&quot;{% url upload %}?X-Progress-ID=&quot;</span> + uuid<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">        req.startTimer<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'X-Progress-ID='</span> + uuid<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">	<span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
{% endblock %}</pre></div></div>

<p>You can download all the completed files from here &#8211; <a href='http://fightingrabbits.com/wp-content/uploads/2009/10/ZipFile.zip'>ZipFile</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://fightingrabbits.com/archives/210/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Nginx &amp; Django on Webfaction &#8211; Part 2</title>
		<link>http://fightingrabbits.com/archives/208</link>
		<comments>http://fightingrabbits.com/archives/208#comments</comments>
		<pubDate>Mon, 21 Sep 2009 19:18:00 +0000</pubDate>
		<dc:creator>Richard Cooper</dc:creator>
				<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://fightingrabbits.com/?p=208</guid>
		<description><![CDATA[Hopefully after finishing Part 1a and Part 1b you have a working Nginx + Django install on Webfaction. In this installment I&#8217;m going to show you how to keep your site running through app failures and server reboots. One of the problems with having our own web stack  running is what happens if the Webfaction [...]]]></description>
			<content:encoded><![CDATA[<p>Hopefully after finishing <a href="http://fightingrabbits.com/archives/139">Part 1a</a> and <a href="http://fightingrabbits.com/archives/160">Part 1b</a> you have a working Nginx + Django install on Webfaction. In this installment I&#8217;m going to show you how to keep your site running through app failures and server reboots.<br />
<span id="more-208"></span><br />
One of the problems with having our own web stack  running is what happens if the Webfaction support team ever need to reboot the server or if our Django App crashes? We could solve this by adding a cron job to restart our stack every few minutes but because Nginx doesn&#8217;t spawn our FCGI Django process it gets quite complex, and we have no easy way to monitor the status.</p>
<p>The solution as suggested <a href="http://forum.webfaction.com/viewtopic.php?id=1981&#038;p=2">here</a>  is to use <a href="http://supervisord.org/">supervisor</a> to control our server processes and then make sure that we have a cron job to check and restart supervisor.</p>
<p><strong>Please don&#8217;t try this on a production site if you don&#8217;t know what you are doing unless you can afford some down time whilst you get it working!</strong></p>
<p>First we need to create a new app listening on port to reserve ourselves a port for supervisor to run on:<br />
<a href="http://fightingrabbits.com/wp-content/uploads/2009/08/create_app.png"><img src="http://fightingrabbits.com/wp-content/uploads/2009/08/create_app-300x176.png" alt="Create A new App" title="Create A new App" width="300" height="176" class="aligncenter size-medium wp-image-142" /></a><br />
And make a note of the port number for later:<br />
<a href="http://fightingrabbits.com/wp-content/uploads/2009/08/app_created.png"><img src="http://fightingrabbits.com/wp-content/uploads/2009/08/app_created-300x199.png" alt="Make a note of the Port Number" title="Make a note of the Port Number" width="300" height="199" class="aligncenter size-medium wp-image-141" /></a><br />
First we need to create a start script for Django so that supervisor can monitor it, use your favourite editor to create a file called runserver.py in your django project directory (/home/&lt;myuser&gt;/webapps/&lt;myapp&gt;/&lt;myproject&gt;/runserver.py) with the following content:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/local/bin/python2.5</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #dc143c;">sys</span>.<span style="color: black;">path</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/home/&lt;myuser&gt;/webapps/&lt;myapp&gt;/&lt;myproject&gt;/'</span><span style="color: black;">&#41;</span>
<span style="color: #dc143c;">sys</span>.<span style="color: black;">path</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/home/&lt;myuser&gt;/webapps/&lt;myapp&gt;/lib/python2.5/django/bin'</span><span style="color: black;">&#41;</span>
<span style="color: #dc143c;">sys</span>.<span style="color: black;">path</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/home/&lt;myuser&gt;/webapps/&lt;myapp&gt;/lib/python2.5/django/'</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
    <span style="color: #ff7700;font-weight:bold;">from</span> flup.<span style="color: black;">server</span>.<span style="color: black;">fcgi_fork</span> <span style="color: #ff7700;font-weight:bold;">import</span> WSGIServer
    <span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">core</span>.<span style="color: black;">handlers</span>.<span style="color: black;">wsgi</span> <span style="color: #ff7700;font-weight:bold;">import</span> WSGIHandler
    WSGIServer<span style="color: black;">&#40;</span>WSGIHandler<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>,maxSpare=<span style="color: #ff4500;">1</span>, maxChildren=<span style="color: #ff4500;">1</span>, debug=<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Remember to change the &lt;myuser&gt; etc to the correct values, save the file and make it executable using:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> +x runserver.py</pre></div></div>

<p>We also need to change our django settings.py file and change the ROOT_URLCONF to:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">ROOT_URLCONF = <span style="color: #483d8b;">'urls'</span></pre></div></div>

<p>Because supervisor can only interact with non daemonized processes we need to make a minor change to our nginx.conf file and add the following line right at the begining:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">daemon off;</pre></div></div>

<p>Next we need to install supervisor:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">easy_install-<span style="color: #000000;">2.5</span> supervisor</pre></div></div>

<p>Then create a file called supervisord.conf in your home directory with the following content (remember to replace &lt;portnumber&gt; with the number from earlier in this post):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">; Webfaction supervisor config file.
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>inet_http_server<span style="color: #7a0874; font-weight: bold;">&#93;</span>          				; inet <span style="color: #7a0874; font-weight: bold;">&#40;</span>TCP<span style="color: #7a0874; font-weight: bold;">&#41;</span> server setings
<span style="color: #007800;">port</span>=127.0.0.1:<span style="color: #000000; font-weight: bold;">&lt;</span>portnumber<span style="color: #000000; font-weight: bold;">&gt;</span>	    			; <span style="color: #7a0874; font-weight: bold;">&#40;</span>ip_address:port specifier, <span style="color: #000000; font-weight: bold;">*</span>:port <span style="color: #000000; font-weight: bold;">for</span> all iface<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">username</span>=<span style="color: #000000; font-weight: bold;">&lt;</span>username<span style="color: #000000; font-weight: bold;">&gt;</span>           				; <span style="color: #7a0874; font-weight: bold;">&#40;</span>default is no username <span style="color: #7a0874; font-weight: bold;">&#40;</span>open server<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">password</span>=<span style="color: #000000; font-weight: bold;">&lt;</span>password<span style="color: #000000; font-weight: bold;">&gt;</span>   	   			           ; <span style="color: #7a0874; font-weight: bold;">&#40;</span>default is no password <span style="color: #7a0874; font-weight: bold;">&#40;</span>open server<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>supervisord<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #007800;">logfile</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/&lt;</span>myuser<span style="color: #000000; font-weight: bold;">&gt;/</span>logs<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #000000; font-weight: bold;">/</span>supervisor<span style="color: #000000; font-weight: bold;">/</span>supervisord.log 		; <span style="color: #7a0874; font-weight: bold;">&#40;</span>main log <span style="color: #c20cb9; font-weight: bold;">file</span>;default <span style="color: #007800;">$CWD</span><span style="color: #000000; font-weight: bold;">/</span>supervisord.log<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">logfile_maxbytes</span>=50MB       						; <span style="color: #7a0874; font-weight: bold;">&#40;</span>max main logfile bytes b4 rotation;default 50MB<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">logfile_backups</span>=<span style="color: #000000;">10</span>          						; <span style="color: #7a0874; font-weight: bold;">&#40;</span>num of main logfile rotation backups;default <span style="color: #000000;">10</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">loglevel</span>=debug               						; <span style="color: #7a0874; font-weight: bold;">&#40;</span>log level;default info; others: debug,warn,trace<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">pidfile</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/&lt;</span>myuser<span style="color: #000000; font-weight: bold;">&gt;/</span>supervisord.pid                          		; <span style="color: #7a0874; font-weight: bold;">&#40;</span>supervisord pidfile;default supervisord.pid<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">nodaemon</span>=<span style="color: #c20cb9; font-weight: bold;">false</span>              						; <span style="color: #7a0874; font-weight: bold;">&#40;</span>start <span style="color: #000000; font-weight: bold;">in</span> foreground <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #c20cb9; font-weight: bold;">true</span>;default <span style="color: #c20cb9; font-weight: bold;">false</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">minfds</span>=<span style="color: #000000;">1024</span>                 						; <span style="color: #7a0874; font-weight: bold;">&#40;</span>min. avail startup <span style="color: #c20cb9; font-weight: bold;">file</span> descriptors;default <span style="color: #000000;">1024</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">minprocs</span>=<span style="color: #000000;">200</span>                						; <span style="color: #7a0874; font-weight: bold;">&#40;</span>min. avail process descriptors;default <span style="color: #000000;">200</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>rpcinterface:supervisor<span style="color: #7a0874; font-weight: bold;">&#93;</span>
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>supervisorctl<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #007800;">serverurl</span>=http:<span style="color: #000000; font-weight: bold;">//</span>127.0.0.1:<span style="color: #000000; font-weight: bold;">&lt;</span>portnumber<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #007800;">username</span>=<span style="color: #000000; font-weight: bold;">&lt;</span>username<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #007800;">password</span>=<span style="color: #000000; font-weight: bold;">&lt;</span>password<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>program:nginx<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #007800;"><span style="color: #7a0874; font-weight: bold;">command</span></span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/&lt;</span>myuser<span style="color: #000000; font-weight: bold;">&gt;/</span>webapps<span style="color: #000000; font-weight: bold;">/&lt;</span>myapp<span style="color: #000000; font-weight: bold;">&gt;/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>nginx <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/&lt;</span>myuser<span style="color: #000000; font-weight: bold;">&gt;/</span>webapps<span style="color: #000000; font-weight: bold;">/&lt;</span>myapp<span style="color: #000000; font-weight: bold;">&gt;/</span>conf<span style="color: #000000; font-weight: bold;">/</span>nginx.conf
<span style="color: #007800;">autostart</span>=<span style="color: #c20cb9; font-weight: bold;">true</span>
<span style="color: #007800;">autorestart</span>=<span style="color: #c20cb9; font-weight: bold;">true</span>
<span style="color: #007800;">redirect_stderr</span>=<span style="color: #c20cb9; font-weight: bold;">true</span>
<span style="color: #007800;">exitcodes</span>=<span style="color: #000000;">0</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>fcgi-program:django<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #007800;">socket</span>=unix:<span style="color: #000000; font-weight: bold;">///</span>home<span style="color: #000000; font-weight: bold;">/&lt;</span>myuser<span style="color: #000000; font-weight: bold;">&gt;/</span>webapps<span style="color: #000000; font-weight: bold;">/&lt;</span>myapp<span style="color: #000000; font-weight: bold;">&gt;/&lt;</span>myproject<span style="color: #000000; font-weight: bold;">&gt;/</span>django.sock
<span style="color: #007800;">process_name</span>=<span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>program_name<span style="color: #7a0874; font-weight: bold;">&#41;</span>s_<span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>process_num<span style="color: #7a0874; font-weight: bold;">&#41;</span>02d
<span style="color: #007800;">numprocs</span>=<span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">command</span> = <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/&lt;</span>myuser<span style="color: #000000; font-weight: bold;">&gt;/</span>webapps<span style="color: #000000; font-weight: bold;">/&lt;</span>myapp<span style="color: #000000; font-weight: bold;">&gt;/&lt;</span>myproject<span style="color: #000000; font-weight: bold;">&gt;/</span>runserver.py  	
<span style="color: #007800;">environment</span>=<span style="color: #007800;">DJANGO_SETTINGS_MODULE</span>=settings
<span style="color: #007800;">autostart</span>=<span style="color: #c20cb9; font-weight: bold;">true</span>
<span style="color: #007800;">autorestart</span>=<span style="color: #c20cb9; font-weight: bold;">true</span>
<span style="color: #007800;">redirect_stderr</span>=<span style="color: #c20cb9; font-weight: bold;">true</span></pre></div></div>

<p>Replace the &lt;username&gt; and &lt;password&gt; in the file above with ones of your choosing (not your webfaction account ones!) Assuming that all the &lt;xxx&gt; bits have been replaced properly we could now start supervisor &#8211; however we would still suffer from the problem of supervisor not being started on a reboot. Let&#8217;s fix that &#8211; create a file called start_supervisor.sh in your home directory with the following content:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash </span>
&nbsp;
<span style="color: #007800;">NAME</span>=supervisord
<span style="color: #007800;">SUPERVISORD</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/&lt;</span>myuser<span style="color: #000000; font-weight: bold;">&gt;/</span>bin<span style="color: #000000; font-weight: bold;">/</span>supervisord
<span style="color: #007800;">SUPERVISORCTL</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/&lt;</span>myuser<span style="color: #000000; font-weight: bold;">&gt;/</span>bin<span style="color: #000000; font-weight: bold;">/</span>supervisorctl
<span style="color: #007800;">PIDFILE</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/&lt;</span>myuser<span style="color: #000000; font-weight: bold;">&gt;/</span>supervisord.pid
<span style="color: #007800;">OPTS</span>=<span style="color: #ff0000;">&quot;-c /home/&lt;myuser&gt;/supervisord.conf&quot;</span>
<span style="color: #007800;">PS</span>=<span style="color: #007800;">$NAME</span>
<span style="color: #007800;">TRUE</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">FALSE</span>=<span style="color: #000000;">0</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-x</span> <span style="color: #007800;">$SUPERVISORD</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${PATH:+$PATH:}</span>/usr/local/bin:/usr/sbin:/sbin:/home/&lt;myuser&gt;/bin:&quot;</span>
&nbsp;
isRunning<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
    pidof_daemon
    <span style="color: #007800;">PID</span>=<span style="color: #007800;">$?</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$PID</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
pidof_daemon<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">PIDS</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">pidof</span> <span style="color: #660033;">-x</span> <span style="color: #007800;">$PS</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
&nbsp;
    <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #007800;">$PIDFILE</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">PIDS2</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$PIDFILE</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$PIDS</span>; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span>&quot;</span> = <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PIDS2</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">done</span>
    <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
start <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Starting Supervisor daemon manager...&quot;</span>
    isRunning
    <span style="color: #007800;">isAlive</span>=<span style="color: #007800;">$?</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${isAlive}</span>&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #007800;">$TRUE</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Supervisor is already running.&quot;</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #007800;">$SUPERVISORD</span> <span style="color: #007800;">$OPTS</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Failed...!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK&quot;</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
stop <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Stopping Supervisor daemon manager...&quot;</span>
    <span style="color: #007800;">$SUPERVISORCTL</span> shutdown <span style="color: #000000; font-weight: bold;">||</span>  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Failed...!&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
  start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    start
	<span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
  stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    stop
	<span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
  restart<span style="color: #000000; font-weight: bold;">|</span>reload<span style="color: #000000; font-weight: bold;">|</span>force-reload<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    stop
    start
    <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<p>we&#8217;ll use this script to start and stop supervisor so we need to make it executable. Now we need to add it to a cron job to make sure that it runs every few minutes (the script checks that supervisor is running so won&#8217;t start multiple instances of it) this will allow us to be back up and running a few minutes after the server comes back up.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">EDITOR</span>=<span style="color: #c20cb9; font-weight: bold;">nano</span> crontab <span style="color: #660033;">-e</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">*/</span><span style="color: #000000;">10</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>; .<span style="color: #000000; font-weight: bold;">/</span>start_supervisor.sh</pre></div></div>

<p>This will run our script every 10 mins. Now if you stop your Django and Nginx processes, cd to your home directory, and run</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>start_supervisor.sh</pre></div></div>

<p>You should now be running on supervisor and your site should be up. If you&#8217;d like to be able to see that status of your processes then mount the app we created at the start on a subdomain such as status.mydomain.com and then browse to that url (you&#8217;ll need to enter the user and password that you put into the supervisor.conf file)<br />
<div id="attachment_252" class="wp-caption aligncenter" style="width: 310px"><a href="http://fightingrabbits.com/wp-content/uploads/2009/09/supervisor.PNG"><img src="http://fightingrabbits.com/wp-content/uploads/2009/09/supervisor-300x97.PNG" alt="Supervisor Website" title="Supervisor Website" width="300" height="97" class="size-medium wp-image-252" /></a><p class="wp-caption-text">Supervisor Website</p></div><br />
<strong>Enjoy!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://fightingrabbits.com/archives/208/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Webfaction Memory Usage Script.</title>
		<link>http://fightingrabbits.com/archives/198</link>
		<comments>http://fightingrabbits.com/archives/198#comments</comments>
		<pubDate>Mon, 07 Sep 2009 19:19:56 +0000</pubDate>
		<dc:creator>Richard Cooper</dc:creator>
				<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://fightingrabbits.com/?p=198</guid>
		<description><![CDATA[This is a nice little script that I found on the Webfaction forums. It will let you know how much memory you are using so that you can avoid going over your limit. The advantage of this script is that it will discount the per-user Apache threads from the main Webfaction Apache instance, which are [...]]]></description>
			<content:encoded><![CDATA[<p>This is a nice little script that I found on the Webfaction forums. It will let you know how much memory you are using so that you can avoid going over your limit. The advantage of this script is that it will discount the per-user Apache threads from the main Webfaction Apache instance, which are not counted towards your memory usage.<br />
<span id="more-198"></span></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/local/bin/python2.5</span>
&nbsp;
<span style="color: #483d8b;">&quot;&quot;&quot;
mem.py - A script which calculates, formats, and displays a customer's
memory usage
&nbsp;
&quot;&quot;&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">subprocess</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
CMD = <span style="color: #483d8b;">&quot;ps -o rss,command -u %s | grep -v peruser | awk '{sum += $1} END {print sum / 1024}'&quot;</span>
MEM = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    proc = <span style="color: #dc143c;">subprocess</span>.<span style="color: black;">Popen</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'groups'</span>, shell=<span style="color: #008000;">True</span>, stdout=<span style="color: #dc143c;">subprocess</span>.<span style="color: black;">PIPE</span><span style="color: black;">&#41;</span>
    proc.<span style="color: black;">wait</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    stdout = proc.<span style="color: black;">stdout</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: #dc143c;">user</span> <span style="color: #ff7700;font-weight:bold;">in</span> stdout.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        proc = <span style="color: #dc143c;">subprocess</span>.<span style="color: black;">Popen</span><span style="color: black;">&#40;</span>CMD <span style="color: #66cc66;">%</span> <span style="color: #dc143c;">user</span>, shell=<span style="color: #008000;">True</span>, stdout=<span style="color: #dc143c;">subprocess</span>.<span style="color: black;">PIPE</span><span style="color: black;">&#41;</span>
        proc.<span style="color: black;">wait</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        MEM<span style="color: black;">&#91;</span><span style="color: #dc143c;">user</span><span style="color: black;">&#93;</span> = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #008000;">float</span><span style="color: black;">&#40;</span>proc.<span style="color: black;">stdout</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">print</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Total Memory Usage: %i MB'</span> <span style="color: #66cc66;">%</span> <span style="color: #008000;">sum</span><span style="color: black;">&#40;</span>MEM.<span style="color: black;">values</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: #dc143c;">user</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">sorted</span><span style="color: black;">&#40;</span>MEM.<span style="color: black;">keys</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">user</span>.<span style="color: black;">ljust</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">15</span><span style="color: black;">&#41;</span>, <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>MEM<span style="color: black;">&#91;</span><span style="color: #dc143c;">user</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>.<span style="color: black;">rjust</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span>, <span style="color: #483d8b;">'MB'</span>
    <span style="color: #ff7700;font-weight:bold;">print</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Note: &quot;Total Memory Usage&quot; is only valid when you execute mem using your<span style="color: #000099; font-weight: bold;">\</span>
 account<span style="color: #000099; font-weight: bold;">\'</span>s primary SSH user.'</span>
    <span style="color: #ff7700;font-weight:bold;">print</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
    main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Download it <a href='http://fightingrabbits.com/wp-content/uploads/2009/09/mem.txt'>here</a> copy it to your server, rename it to mem.py and make it executable.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mv</span> mem.txt mem.py
<span style="color: #c20cb9; font-weight: bold;">chmod</span> +x mem.py</pre></div></div>

<p>You can then call it using:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">python2.5 .<span style="color: #000000; font-weight: bold;">/</span>mem.py</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://fightingrabbits.com/archives/198/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx &amp; Django on Webfaction (Part&#160;1b) – Configuring</title>
		<link>http://fightingrabbits.com/archives/160</link>
		<comments>http://fightingrabbits.com/archives/160#comments</comments>
		<pubDate>Mon, 07 Sep 2009 12:18:46 +0000</pubDate>
		<dc:creator>Richard Cooper</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[Setup]]></category>
		<category><![CDATA[webfaction]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://fightingrabbits.com/?p=160</guid>
		<description><![CDATA[In Part 1a of this series we compiled Nginx and Installed Django in this next part we are going to configure nginx and Django and get our welcome page displaying. First lets configure nginx, the default conf file looks like this: #user nobody; worker_processes 1; &#160; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>In Part 1a of this series we compiled Nginx and Installed Django in this next part we are going to configure nginx and Django and get our welcome page displaying.</p>
<p>First lets configure nginx, the default conf file looks like this:</p>
<p><span id="more-160"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#user  nobody;</span>
worker_processes  <span style="color: #000000;">1</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">#error_log  logs/error.log;</span>
<span style="color: #666666; font-style: italic;">#error_log  logs/error.log  notice;</span>
<span style="color: #666666; font-style: italic;">#error_log  logs/error.log  info;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#pid        logs/nginx.pid;</span>
&nbsp;
&nbsp;
events <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    worker_connections  <span style="color: #000000;">1024</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
&nbsp;
http <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    include       mime.types;
    default_type  application<span style="color: #000000; font-weight: bold;">/</span>octet-stream;
&nbsp;
    <span style="color: #666666; font-style: italic;">#log_format  main  '$remote_addr - $remote_user [$time_local] &quot;$request&quot; '</span>
    <span style="color: #666666; font-style: italic;">#                  '$status $body_bytes_sent &quot;$http_referer&quot; '</span>
    <span style="color: #666666; font-style: italic;">#                  '&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;';</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">#access_log  logs/access.log  main;</span>
&nbsp;
    sendfile        on;
    <span style="color: #666666; font-style: italic;">#tcp_nopush     on;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">#keepalive_timeout  0;</span>
    keepalive_timeout  <span style="color: #000000;">65</span>;
&nbsp;
    <span style="color: #666666; font-style: italic;">#gzip  on;</span>
&nbsp;
    server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        listen       <span style="color: #000000;">80</span>;
        server_name  localhost;
&nbsp;
        <span style="color: #666666; font-style: italic;">#charset koi8-r;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">#access_log  logs/host.access.log  main;</span>
&nbsp;
        location <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
            root   html;
            index  index.html index.htm;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">#error_page  404              /404.html;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># redirect server error pages to the static page /50x.html</span>
        <span style="color: #666666; font-style: italic;">#</span>
        error_page   <span style="color: #000000;">500</span> <span style="color: #000000;">502</span> <span style="color: #000000;">503</span> <span style="color: #000000;">504</span>  <span style="color: #000000; font-weight: bold;">/</span>50x.html;
        location = <span style="color: #000000; font-weight: bold;">/</span>50x.html <span style="color: #7a0874; font-weight: bold;">&#123;</span>
            root   html;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># proxy the PHP scripts to Apache listening on 127.0.0.1:80</span>
        <span style="color: #666666; font-style: italic;">#</span>
        <span style="color: #666666; font-style: italic;">#location ~ \.php$ {</span>
        <span style="color: #666666; font-style: italic;">#    proxy_pass   http://127.0.0.1;</span>
        <span style="color: #666666; font-style: italic;">#}</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000</span>
        <span style="color: #666666; font-style: italic;">#</span>
        <span style="color: #666666; font-style: italic;">#location ~ \.php$ {</span>
        <span style="color: #666666; font-style: italic;">#    root           html;</span>
        <span style="color: #666666; font-style: italic;">#    fastcgi_pass   127.0.0.1:9000;</span>
        <span style="color: #666666; font-style: italic;">#    fastcgi_index  index.php;</span>
        <span style="color: #666666; font-style: italic;">#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;</span>
        <span style="color: #666666; font-style: italic;">#    include        fastcgi_params;</span>
        <span style="color: #666666; font-style: italic;">#}</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># deny access to .htaccess files, if Apache's document root</span>
        <span style="color: #666666; font-style: italic;"># concurs with nginx's one</span>
        <span style="color: #666666; font-style: italic;">#</span>
        <span style="color: #666666; font-style: italic;">#location ~ /\.ht {</span>
        <span style="color: #666666; font-style: italic;">#    deny  all;</span>
        <span style="color: #666666; font-style: italic;">#}</span>
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #666666; font-style: italic;"># another virtual host using mix of IP-, name-, and port-based configuration</span>
    <span style="color: #666666; font-style: italic;">#</span>
    <span style="color: #666666; font-style: italic;">#server {</span>
    <span style="color: #666666; font-style: italic;">#    listen       8000;</span>
    <span style="color: #666666; font-style: italic;">#    listen       somename:8080;</span>
    <span style="color: #666666; font-style: italic;">#    server_name  somename  alias  another.alias;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">#    location / {</span>
    <span style="color: #666666; font-style: italic;">#        root   html;</span>
    <span style="color: #666666; font-style: italic;">#        index  index.html index.htm;</span>
    <span style="color: #666666; font-style: italic;">#    }</span>
    <span style="color: #666666; font-style: italic;">#}</span>
&nbsp;
&nbsp;
    <span style="color: #666666; font-style: italic;"># HTTPS server</span>
    <span style="color: #666666; font-style: italic;">#</span>
    <span style="color: #666666; font-style: italic;">#server {</span>
    <span style="color: #666666; font-style: italic;">#    listen       443;</span>
    <span style="color: #666666; font-style: italic;">#    server_name  localhost;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">#    ssl                  on;</span>
    <span style="color: #666666; font-style: italic;">#    ssl_certificate      cert.pem;</span>
    <span style="color: #666666; font-style: italic;">#    ssl_certificate_key  cert.key;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">#    ssl_session_timeout  5m;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">#    ssl_protocols  SSLv2 SSLv3 TLSv1;</span>
    <span style="color: #666666; font-style: italic;">#    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;</span>
    <span style="color: #666666; font-style: italic;">#    ssl_prefer_server_ciphers   on;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">#    location / {</span>
    <span style="color: #666666; font-style: italic;">#        root   html;</span>
    <span style="color: #666666; font-style: italic;">#        index  index.html index.htm;</span>
    <span style="color: #666666; font-style: italic;">#    }</span>
    <span style="color: #666666; font-style: italic;">#}</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Now that we have seen the default file let&#8217;s back it up and start from scratch :)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>webapps<span style="color: #000000; font-weight: bold;">/&lt;</span>myapp<span style="color: #000000; font-weight: bold;">&gt;/</span>conf
<span style="color: #c20cb9; font-weight: bold;">mv</span> nginx.conf nginx.conf.bak
<span style="color: #c20cb9; font-weight: bold;">nano</span> nginx.conf</pre></div></div>

<p>First we need to set our basic Nginx properties:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#2 workers x 1024 connections gives us some resiliance and should be enough for most sites.</span>
worker_processes <span style="color: #000000;">2</span>;
&nbsp;
events <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    worker_connections <span style="color: #000000;">1024</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
http <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    include             mime.types;
    default_type        application<span style="color: #000000; font-weight: bold;">/</span>octet-stream;	
&nbsp;
    server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        listen  myport;
        server_name mydomain;
        <span style="color: #666666; font-style: italic;">#You will need to change the next line to something bigger if you want to accept uploads over 5Mb</span>
        client_max_body_size 5m;
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Remember to replace myport and mydomain with your actual values from Part 1a!</p>
<p>Next let&#8217;s setup our http server config to serve our static media (You could setup a static only app to serve your media from the main Apache Instance, but let&#8217;s do it this way as a learning exercise.) We are going to add one location for all our static media, and one location just to serve the favicon. Edit the http section to look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">http <span style="color: #7a0874; font-weight: bold;">&#123;</span>
&nbsp;
    include             mime.types;
    default_type        application<span style="color: #000000; font-weight: bold;">/</span>octet-stream;	
&nbsp;
    server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        listen  myport;
        server_name mydomain;
        client_max_body_size 5m;
&nbsp;
        location <span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
            <span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/&lt;</span>myusername<span style="color: #000000; font-weight: bold;">&gt;/</span>webapps<span style="color: #000000; font-weight: bold;">/&lt;</span>myapp<span style="color: #000000; font-weight: bold;">&gt;/&lt;</span>myproject<span style="color: #000000; font-weight: bold;">&gt;/</span>media<span style="color: #000000; font-weight: bold;">/</span>;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        location ~<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>favicon.ico <span style="color: #7a0874; font-weight: bold;">&#123;</span>
            root <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/&lt;</span>myusername<span style="color: #000000; font-weight: bold;">&gt;/</span>webapps<span style="color: #000000; font-weight: bold;">/&lt;</span>myapp<span style="color: #000000; font-weight: bold;">&gt;/&lt;</span>myproject<span style="color: #000000; font-weight: bold;">&gt;/</span>media<span style="color: #000000; font-weight: bold;">/</span>img<span style="color: #000000; font-weight: bold;">/</span>;
            <span style="color: #666666; font-style: italic;">#Let's not waste time logging this access...</span>
            access_log off;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Again remember to replace <myusername>, <myapp> and <myproject> with your actual values.</p>
<p>Right now let&#8217;s setup nginx to talk to our fastcgi django process add this section into the configuration file after the favicon.ico location:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">location <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    proxy_set_header  	         X-Real-IP  <span style="color: #007800;">$remote_addr</span>;
    proxy_set_header             X-Forwarded-For <span style="color: #007800;">$proxy_add_x_forwarded_for</span>;
    fastcgi_pass                unix:<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/&lt;</span>myusername<span style="color: #000000; font-weight: bold;">&gt;/</span>webapps<span style="color: #000000; font-weight: bold;">/&lt;</span>myapp<span style="color: #000000; font-weight: bold;">&gt;/&lt;</span>myproject<span style="color: #000000; font-weight: bold;">&gt;/</span>django.sock;
    fastcgi_pass_header          Authorization;          
    fastcgi_hide_header          X-Accel-Redirect;
    fastcgi_hide_header          X-Sendfile;
    fastcgi_intercept_errors     off;
    include                        fastcgi_params;
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Our nginx.conf should now look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#2 workers x 1024 connections gives us some resiliance and should be enough for most sites.</span>
worker_processes <span style="color: #000000;">2</span>;
&nbsp;
events <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    worker_connections <span style="color: #000000;">1024</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
http <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    include             mime.types;
    default_type        application<span style="color: #000000; font-weight: bold;">/</span>octet-stream;	
&nbsp;
    server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        listen  myport;
        server_name mydomain;
        client_max_body_size 5m;
&nbsp;
        location <span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
           <span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/&lt;</span>myusername<span style="color: #000000; font-weight: bold;">&gt;/</span>webapps<span style="color: #000000; font-weight: bold;">/&lt;</span>myapp<span style="color: #000000; font-weight: bold;">&gt;/&lt;</span>myproject<span style="color: #000000; font-weight: bold;">&gt;/</span>media<span style="color: #000000; font-weight: bold;">/</span>;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        location ~<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>favicon.ico <span style="color: #7a0874; font-weight: bold;">&#123;</span>
           root <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/&lt;</span>myusername<span style="color: #000000; font-weight: bold;">&gt;/</span>webapps<span style="color: #000000; font-weight: bold;">/&lt;</span>myapp<span style="color: #000000; font-weight: bold;">&gt;/&lt;</span>myproject<span style="color: #000000; font-weight: bold;">&gt;/</span>media<span style="color: #000000; font-weight: bold;">/</span>img<span style="color: #000000; font-weight: bold;">/</span>;
           <span style="color: #666666; font-style: italic;">#Let's not waste time logging this access...</span>
           access_log off;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        location <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
            proxy_set_header  	        X-Real-IP  <span style="color: #007800;">$remote_addr</span>;
            proxy_set_header            X-Forwarded-For <span style="color: #007800;">$proxy_add_x_forwarded_for</span>;
            fastcgi_pass                unix:<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/&lt;</span>myusername<span style="color: #000000; font-weight: bold;">&gt;/</span>webapps<span style="color: #000000; font-weight: bold;">/&lt;</span>myapp<span style="color: #000000; font-weight: bold;">&gt;/&lt;</span>myproject<span style="color: #000000; font-weight: bold;">&gt;/</span>django.sock;
            fastcgi_pass_header         Authorization;          
            fastcgi_hide_header         X-Accel-Redirect;
            fastcgi_hide_header         X-Sendfile;
            fastcgi_intercept_errors    off;
            include                     fastcgi_params;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>We need to make a slight change to the fastcgi_params file that is being included so that it works correctly with Django. Comment out the following line by placing a # in front of it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">fastcgi_param  SCRIPT_NAME		 <span style="color: #007800;">$fastcgi_script_name</span>;</pre></div></div>

<p>and add this just above it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">fastcgi_param  PATH_INFO          <span style="color: #007800;">$fastcgi_script_name</span>;</pre></div></div>

<p>You can download the complete sample files here <a href='http://fightingrabbits.com/wp-content/uploads/2009/09/configfiles.zip'>zip</a> / <a href='http://fightingrabbits.com/wp-content/uploads/2009/09/configfiles.tar.gz'>gz</a></p>
<p>Django configuration is pretty simple as we can use the default settings file for now:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Django settings for myproject project.</span>
&nbsp;
DEBUG = True
TEMPLATE_DEBUG = DEBUG
&nbsp;
ADMINS = <span style="color: #7a0874; font-weight: bold;">&#40;</span>
    <span style="color: #666666; font-style: italic;"># ('Your Name', 'your_email@domain.com'),</span>
<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
MANAGERS = ADMINS
&nbsp;
DATABASE_ENGINE = <span style="color: #ff0000;">''</span>           <span style="color: #666666; font-style: italic;"># 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.</span>
DATABASE_NAME = <span style="color: #ff0000;">''</span>             <span style="color: #666666; font-style: italic;"># Or path to database file if using sqlite3.</span>
DATABASE_USER = <span style="color: #ff0000;">''</span>             <span style="color: #666666; font-style: italic;"># Not used with sqlite3.</span>
DATABASE_PASSWORD = <span style="color: #ff0000;">''</span>         <span style="color: #666666; font-style: italic;"># Not used with sqlite3.</span>
DATABASE_HOST = <span style="color: #ff0000;">''</span>             <span style="color: #666666; font-style: italic;"># Set to empty string for localhost. Not used with sqlite3.</span>
DATABASE_PORT = <span style="color: #ff0000;">''</span>             <span style="color: #666666; font-style: italic;"># Set to empty string for default. Not used with sqlite3.</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Local time zone for this installation. Choices can be found here:</span>
<span style="color: #666666; font-style: italic;"># http://en.wikipedia.org/wiki/List_of_tz_zones_by_name</span>
<span style="color: #666666; font-style: italic;"># although not all choices may be available on all operating systems.</span>
<span style="color: #666666; font-style: italic;"># If running in a Windows environment this must be set to the same as your</span>
<span style="color: #666666; font-style: italic;"># system time zone.</span>
TIME_ZONE = <span style="color: #ff0000;">'America/Chicago'</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Language code for this installation. All choices can be found here:</span>
<span style="color: #666666; font-style: italic;"># http://www.i18nguy.com/unicode/language-identifiers.html</span>
LANGUAGE_CODE = <span style="color: #ff0000;">'en-us'</span>
&nbsp;
SITE_ID = <span style="color: #000000;">1</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># If you set this to False, Django will make some optimizations so as not</span>
<span style="color: #666666; font-style: italic;"># to load the internationalization machinery.</span>
USE_I18N = True
&nbsp;
<span style="color: #666666; font-style: italic;"># Absolute path to the directory that holds media.</span>
<span style="color: #666666; font-style: italic;"># Example: &quot;/home/media/media.lawrence.com/&quot;</span>
MEDIA_ROOT = <span style="color: #ff0000;">''</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># URL that handles the media served from MEDIA_ROOT. Make sure to use a</span>
<span style="color: #666666; font-style: italic;"># trailing slash if there is a path component (optional in other cases).</span>
<span style="color: #666666; font-style: italic;"># Examples: &quot;http://media.lawrence.com&quot;, &quot;http://example.com/media/&quot;</span>
MEDIA_URL = <span style="color: #ff0000;">''</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a</span>
<span style="color: #666666; font-style: italic;"># trailing slash.</span>
<span style="color: #666666; font-style: italic;"># Examples: &quot;http://foo.com/media/&quot;, &quot;/media/&quot;.</span>
ADMIN_MEDIA_PREFIX = <span style="color: #ff0000;">'/media/'</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Make this unique, and don't share it with anybody.</span>
SECRET_KEY = <span style="color: #ff0000;">'4#(%&amp;p)^37k2ihr-q-k73qau44ec&amp;8k==gyxb)1+$pck@4+qp='</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># List of callables that know how to import templates from various sources.</span>
TEMPLATE_LOADERS = <span style="color: #7a0874; font-weight: bold;">&#40;</span>
    <span style="color: #ff0000;">'django.template.loaders.filesystem.load_template_source'</span>,
    <span style="color: #ff0000;">'django.template.loaders.app_directories.load_template_source'</span>,
<span style="color: #666666; font-style: italic;">#     'django.template.loaders.eggs.load_template_source',</span>
<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
MIDDLEWARE_CLASSES = <span style="color: #7a0874; font-weight: bold;">&#40;</span>
    <span style="color: #ff0000;">'django.middleware.common.CommonMiddleware'</span>,
    <span style="color: #ff0000;">'django.contrib.sessions.middleware.SessionMiddleware'</span>,
    <span style="color: #ff0000;">'django.contrib.auth.middleware.AuthenticationMiddleware'</span>,
<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
ROOT_URLCONF = <span style="color: #ff0000;">'myproject.urls'</span>
&nbsp;
TEMPLATE_DIRS = <span style="color: #7a0874; font-weight: bold;">&#40;</span>
    <span style="color: #666666; font-style: italic;"># Put strings here, like &quot;/home/html/django_templates&quot; or &quot;C:/www/django/templates&quot;.</span>
    <span style="color: #666666; font-style: italic;"># Always use forward slashes, even on Windows.</span>
    <span style="color: #666666; font-style: italic;"># Don't forget to use absolute paths, not relative paths.</span>
<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
INSTALLED_APPS = <span style="color: #7a0874; font-weight: bold;">&#40;</span>
    <span style="color: #ff0000;">'django.contrib.auth'</span>,
    <span style="color: #ff0000;">'django.contrib.contenttypes'</span>,
    <span style="color: #ff0000;">'django.contrib.sessions'</span>,
    <span style="color: #ff0000;">'django.contrib.sites'</span>,
<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Finally we need to start our servers:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>webapps<span style="color: #000000; font-weight: bold;">/&lt;</span>myapp<span style="color: #000000; font-weight: bold;">&gt;/</span>
.<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>nginx
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">&lt;</span>myproject<span style="color: #000000; font-weight: bold;">&gt;</span>
python2.5 manage.py runfcgi <span style="color: #007800;">maxchildren</span>=<span style="color: #000000;">1</span> <span style="color: #007800;">maxspare</span>=<span style="color: #000000;">1</span> <span style="color: #007800;">method</span>=prefork <span style="color: #007800;">socket</span>=<span style="color: #007800;">$PWD</span><span style="color: #000000; font-weight: bold;">/</span>django.sock <span style="color: #007800;">pidfile</span>=<span style="color: #007800;">$PWD</span><span style="color: #000000; font-weight: bold;">/</span>django.pid <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span> $</pre></div></div>

<p>If you haven&#8217;t done it already mount your app in a domain from the webfaction control panel and then browse to the correct url and you should see the following:</p>
<div id="attachment_162" class="wp-caption aligncenter" style="width: 310px"><a href="http://fightingrabbits.com/wp-content/uploads/2009/08/django-app.png"><img src="http://fightingrabbits.com/wp-content/uploads/2009/08/django-app-300x107.png" alt="Django Welcome Screen" title="Django Welcome Screen" width="300" height="107" class="size-medium wp-image-162" /></a><p class="wp-caption-text">Django Welcome Screen</p></div>
<p>So there you have it &#8211; we have installed and configured Nginx + Django however we still have a few thing&#8217;s to do&#8230; In Part 2 I&#8217;ll show you a couple of ways to make sure that our site isn&#8217;t down for long if the web-server is rebooted or Django crashes.</p>
<p>In Part 3 I&#8217;ll show you how to hand off file uploads to Nginx and get a fancy upload progress bar into the bargin :D</p>
<p>This post was brought to you by the letters L and A and the following websites.</p>
<p><a href="http://forum.webfaction.com/viewtopic.php?id=1981">http://forum.webfaction.com/viewtopic.php?id=1981</a></p>
<p><a href="https://calomel.org/nginx.html">https://calomel.org/nginx.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fightingrabbits.com/archives/160/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Make PayPal IPN send Address Data</title>
		<link>http://fightingrabbits.com/archives/135</link>
		<comments>http://fightingrabbits.com/archives/135#comments</comments>
		<pubDate>Mon, 03 Aug 2009 22:49:07 +0000</pubDate>
		<dc:creator>Richard Cooper</dc:creator>
				<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://fightingrabbits.com/?p=135</guid>
		<description><![CDATA[Another memory jogger&#8230; If you want address data returned by PayPal IPN then you need to set the no_shipping value to 2 1 &#60;input type=&#34;hidden&#34; name=&#34;no_shipping&#34; value=&#34;2&#34;&#62;]]></description>
			<content:encoded><![CDATA[<p>Another memory jogger&#8230;</p>
<p>If you want address data returned by PayPal IPN then you need to set the no_shipping value to 2</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">      &lt;input type=&quot;hidden&quot; name=&quot;no_shipping&quot; value=&quot;2&quot;&gt;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://fightingrabbits.com/archives/135/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Win a free exam voucher from Microsoft Learning&#8230;</title>
		<link>http://fightingrabbits.com/archives/119</link>
		<comments>http://fightingrabbits.com/archives/119#comments</comments>
		<pubDate>Thu, 18 Jun 2009 14:07:48 +0000</pubDate>
		<dc:creator>Richard Cooper</dc:creator>
				<category><![CDATA[Competition]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[Exams]]></category>
		<category><![CDATA[Learing]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://fightingrabbits.com/?p=119</guid>
		<description><![CDATA[Born to Learn (Microsoft Learning) are giving away three prometric exam vouchers each day until 30th June! All you have to do is subscribe to the RSS feed, and post a comment on the Born to Learn blog post available at the following URL&#8230; Have you Subscribed to our RSS feed? Tell us to win [...]]]></description>
			<content:encoded><![CDATA[<p>Born to Learn (Microsoft Learning) are giving away three prometric exam vouchers each day until 30th June!</p>
<p>All you have to do is subscribe to the RSS feed, and post a comment on the Born to Learn blog post available at the following URL&#8230;</p>
<p><a href="http://borntolearn.mslearn.net/2009/06/have-you-subscribed-to-our-rss-feed-tell-us-to-win-a-free-exam/comment-page-2">Have you Subscribed to our RSS feed? Tell us to win a free exam!</a>.</p>
<p>Good Luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://fightingrabbits.com/archives/119/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>hCard Photo&#8217;s</title>
		<link>http://fightingrabbits.com/archives/113</link>
		<comments>http://fightingrabbits.com/archives/113#comments</comments>
		<pubDate>Sun, 07 Jun 2009 09:50:20 +0000</pubDate>
		<dc:creator>Richard Cooper</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[#fowd09]]></category>

		<guid isPermaLink="false">http://fightingrabbits.com/?p=113</guid>
		<description><![CDATA[We recently soft launched a minor site for friend, with an hCard enhanced contact page and a link to transform the hCard into a vCard using the http://technorati.com/contacts/ web-service. The &#8220;client&#8221; was over the moon, but asked if it was possible to include their logo on the vCard that was produced. Now I know from [...]]]></description>
			<content:encoded><![CDATA[<p>We recently soft launched a minor site for friend, with an hCard enhanced contact page and a link to transform the hCard into a vCard using the <a href="http://technorati.com/contacts/">http://technorati.com/contacts/</a> web-service. The &#8220;client&#8221; was over the moon, but asked if it was possible to include their logo on the vCard that was produced. Now I know from the specs that both vCard and hCard support a photo section but getting it to work wasn&#8217;t simple.</p>
<ol>
<li>The <a href="http://technorati.com/contacts/">http://technorati.com/contacts/</a> uses an older version of Brian Suda&#8217;s X2V which doesn&#8217;t seem to support PHOTO:</li>
<li>vCard doesn&#8217;t appear to support my favoured image format of PNG</li>
</ol>
<p>To work around these we implemented our own web service wrapping the latest versions of the X2V transforms &#8211; you can read about that <a href="http://fightingrabbits.com/archives/42">here</a>, I then converted the image to BMP (the old timers format of choice!) However I <strong>STILL </strong>could not get the logo to show in any of the windows clients. Apparently Outlook and Windows Mail, etc. don&#8217;t support a URI for the PHOTO:, even though the vCard spec allows this.</p>
<p>In the end I had to use the little <span style="text-decoration: line-through;">known</span> used &lt;img src= &#8220;data:image/bmp;base64,xxxxxxxx&#8221; /&gt; with a base64 encoded bmp image replacing the xxxxxx to include the actual binary data for the image into the hCard, and thus into the transformed vCard.</p>
<p>The live page can be found <a href="http://www.lionheartinsurance.co.uk/contact.html">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://fightingrabbits.com/archives/113/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Why free software is worth what you pay for it&#8230;</title>
		<link>http://fightingrabbits.com/archives/38</link>
		<comments>http://fightingrabbits.com/archives/38#comments</comments>
		<pubDate>Mon, 13 Apr 2009 11:09:02 +0000</pubDate>
		<dc:creator>Richard Cooper</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[rant]]></category>
		<category><![CDATA[Software.]]></category>

		<guid isPermaLink="false">http://fightingrabbits.com/?p=38</guid>
		<description><![CDATA[We have recently swapped from running our virtual machines in VMWare  to Sun&#8217;s Virtual Box. The performance of virtual box is equal if not better than VMWare, and we will save quite a bit of money on licenses, as all our users would require the workstation version of VMWare. All was well with this plan [...]]]></description>
			<content:encoded><![CDATA[<p>We have recently swapped from running our virtual machines in VMWare  to Sun&#8217;s Virtual Box. The performance of virtual box is equal if not better than VMWare, and we will save quite a bit of money on licenses, as all our users would require the workstation version of VMWare. All was well with this plan until we needed to shrink some of the machines after restoring large DB backups onto them. The command to do this is given as <em>&#8220;VBoxManage modifyhd MyMachine.vdi compact&#8221;</em> unfortunatly the output from this is currently:- <em> &#8221;Error: Shrink hard disk operation is not available!&#8221;  <span style="font-style: normal;">You can see the help ticket for this at <a href="http://www.virtualbox.org/ticket/2833">http://www.virtualbox.org/ticket/2833</a> and it makes pretty horrific reading if you are a fan of open source and expect decent customer support. </span></em></p>
<p>This brings me onto the rant section of this blog. If this was paid for software I could influence the decision &#8211; I could take my cash elsewhere, I could ask to have it fixed as part of my support contract, or several other routes to resolution. As this is &#8220;Free&#8221; software I am reduced to arguing with someone in a defect log item as to whether my issue (and several other peoples as well judging by the defect log) is going to get fixed.</p>
<p>And with comments like <strong><em>&#8220;You are in no position to tell us what to do or not. No amount of complaints from your side will change the priority of this issue.&#8221; </em></strong>it&#8217;s nice to know we are valued customers&#8230;</p>
<p>At the end of it all however we are still going to use VirtualBox, and I am just going to have to hope that Sun will ask their support staff to be a little friendlier.</p>
]]></content:encoded>
			<wfw:commentRss>http://fightingrabbits.com/archives/38/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My Tool Chain&#8230;</title>
		<link>http://fightingrabbits.com/archives/28</link>
		<comments>http://fightingrabbits.com/archives/28#comments</comments>
		<pubDate>Sat, 06 Dec 2008 18:42:13 +0000</pubDate>
		<dc:creator>Richard Cooper</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://fightingrabbits.com/?p=28</guid>
		<description><![CDATA[As a developer I must use one of the strangest tool chains around as I combine FOSS and Microsoft tools freely. For my Platform I use something I like to call VIMP.NET &#8211; running Vista, IIS7, MySQL, Python and .NET. I&#8217;m using Vista Ultimate with the additional &#8220;Subsystem for UNIX-based Applications (SUA)&#8221; installed to give [...]]]></description>
			<content:encoded><![CDATA[<p>As a developer I must use one of the strangest tool chains around as I combine FOSS and Microsoft tools freely.</p>
<p>For my Platform I use something I like to call VIMP.NET &#8211; running Vista, IIS7, MySQL, Python and .NET. I&#8217;m using Vista Ultimate with the additional &#8220;Subsystem for UNIX-based Applications (SUA)&#8221; installed to give me access to commands like ll, and touch, as I like to have a couple of command windows open to allow me to quickly create or copy files, whilst I&#8217;m developing. </p>
<p>For a web development framework I either use the <a href="http://www.djangoproject.com/">Django</a> framework which I find a good fit with Python and my coding style or Visual Basic .NET with the .NET3.5 Framework which is still my language of choice when costs and interoperablity aren&#8217;t a factor.</p>
<p>For a development environment I use a combination of <a href="http://www.activestate.com/Products/komodo_ide/komodo_edit.mhtml">Komodo</a>, <a href="http://notepad-plus.sourceforge.net/uk/site.htm">Notepad++</a>, <a href="http://msdn.microsoft.com/en-us/vstudio/default.aspx">Visual Studio 2008</a> and <a href="http://www.microsoft.com/expression/products/Overview.aspx?key=web">Microsoft Expression Web</a>. Komodo is used for writing Django/Python code, Notepad++ used for JavaScript, some Django, VBScript and XML, and VS2008 is used for .NET, the small amount of SilverLight development I do, and debugging my (very buggy :) )JavaScript. (I Use <a href="http://jquery.com/">jQuery</a> for my JavaScript Framework as again it fits well with my coding style). For (x)HTML\CSS code I really like Expression Web, it has one or two minor &#8220;quirks&#8221; but I find it much easier to use compared with things like DreamWeaver.</p>
<p>For image editing, doing quick mockups of designs or alterations, or making placeholder images until I get the proper artwork from <a href="http://lollylulive.com">lollylu</a>, I use <a href="http://www.adobe.com/products/fireworks/">Adobe Fireworks</a> which is ideal for web use, and I don&#8217;t know how I coped editing images until I bought a copy of this.</p>
<p>For Version control I use SVN both &#8220;managed hosted&#8221; at <a href="http://beanstalkapp.com/">beanstalk</a> and &#8220;self hosted&#8221; on my web account with <a href="http://www.webfaction.com">WebFaction</a>. I use <a href="http://tortoisesvn.net/downloads">TortoiseSVN</a> for my windows SVN client as I really like its integration with windows explorer. I also have to use <a href="http://git.or.cz/">Git</a> to get some Django stuff from GitHub, and SourceSafe for VB but I don&#8217;t like to talk about that :)</p>
<p>For issue tracking I use <a href="http://lighthouseapp.com/">lighthouse</a> which suits my needs as it integrates well with beanstalk and as it is a managed hosted service means I don&#8217;t have much admin to do for it.</p>
<p>For code releases I use <a href="http://filezilla-project.org/">FileZilla</a> as my FTP Client, and <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">PuTTY</a> for my SSH client. I&#8217;m also trying to get <a href="http://www.nongnu.org/fab/">Fabric</a> (An open source deployment tool for Django) to work on windows, although currently I just SSH to my web account and use a custom script to pull from SVN onto my test server and change the settings file over.</p>
<p>If anybody out there uses a stranger combination of tools, please let me know :)</p>
]]></content:encoded>
			<wfw:commentRss>http://fightingrabbits.com/archives/28/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Managing Programmers is like herding cats&#8230;.</title>
		<link>http://fightingrabbits.com/archives/6</link>
		<comments>http://fightingrabbits.com/archives/6#comments</comments>
		<pubDate>Fri, 24 Oct 2008 00:02:52 +0000</pubDate>
		<dc:creator>Richard Cooper</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[humor]]></category>

		<guid isPermaLink="false">http://fightingrabbits.com/?p=6</guid>
		<description><![CDATA[Herding Cats]]></description>
			<content:encoded><![CDATA[<p><a href="http://uk.youtube.com/watch?v=1SmgLtg1Izw">Herding Cats</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fightingrabbits.com/archives/6/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
