Browse files

Updates for Apache, mod_wsgi, Gunicorn, Mingus.

  • Loading branch information...
1 parent c32e228 commit 4b33cf73128216b8ecc561e0d4397337f9638b98 @jacobian jacobian committed Mar 10, 2011
@@ -13,9 +13,6 @@ ServerAdmin
# Standalone server.
Listen *:80
-# To become a backend for a load balancer, uncomment below and fix the IP.
-# Listen 10.X.X.X:8000
# Worker MPM features
@@ -69,7 +66,7 @@ DocumentRoot "/home/web/static"
# And finally the app config.
-WSGIScriptAlias / "/home/web/django-deployment-workshop/fumblerooski-site/bin/django.wsgi"
+WSGIScriptAlias / "/home/web/myblog/mingus.wsgi"
@@ -1,37 +1,35 @@
The tutorial's first fabfile: automate deployment onto a single server.
-If you have Fabric installed system-wide, run with::
+Run with::
- fab -f <command>
-The buildout in ``fumblerooski-site`` has Fabric, too, so you can::
- fumblerooski-site/bin/fab -f ../fabfiles/ <command>
+ fab -f fabfiles/ <command>
+Expects to be run from the parent directory.
-from __future__ import with_statement
import os
from fabric.api import *
# I have entries in /etc/hosts which make these names work.
# If I didn't, I'd just use IP addresses.
-env.hosts = ['oscon-web1']
+env.hosts = ['pyweb-web1']
env.user = 'root'
-env.code_root = "/home/web/django-deployment-workshop"
-env.buildout_root = os.path.join(env.code_root, "fumblerooski-site")
+# Constants for where everything lives on the server.
+env.root = "/home/web/myblog"
def push():
"Push out new code to the server."
with cd(env.code_root):
run("git pull")
+ put("mingus-config/", "%(root)s/django-mingus/mingus/" % env)
+ put("mingus-config/mingus.wsgi", "%(root)s/mingus.wsgi" % env)
-def buildout():
- "Run the buildout remotely."
- with cd(env.buildout_root):
- run("./bin/buildout")
+def update_dependencies():
+ "Update Mingus' requirements remotely."
+ put("mingus-config/requirements.txt", "%s/requirements.txt")
+ run("%(root)s/bin/pip install -r %(rot)s/requirements.txt" % env)
def reload():
"Reload Apache to pick up new code changes."
@@ -0,0 +1,28 @@
+import os
+import site
+import sys
+# Add the virtualenv packages to the site directory. This uses the technique
+# described at
+# Remember original sys.path.
+prev_sys_path = list(sys.path)
+# Add the virtualenv site-packages to the site packages
+# Reorder sys.path so the new directories are at the front.
+new_sys_path = []
+for item in list(sys.path):
+ if item not in prev_sys_path:
+ new_sys_path.append(item)
+ sys.path.remove(item)
+sys.path[:0] = new_sys_path
+# Add the app code to the path
+# Now do DJANGO_SETTINGS_MODULE and create the WSGI app.
+os.environ['DJANGO_SETTINGS_MODULE'] = 'mingus.settings'
+import django.core.handlers.wsgi
+application = django.core.handlers.wsgi.WSGIHandler()
@@ -0,0 +1,43 @@
+-e git://
+-e git://
+-e hg+
+-e git://
+-e hg+
+-e svn+
+-e git://
+-e git://
+-e git://
+-e svn+
+-e git://
+-e git://
+-e git://
+-e git://
+#-e hg+
+-e git+
+-e git://
+-e svn+
+-e git://
+-e hg+
+-e git://
+-e git://
+-e hg+
+-e svn+
+-e git://
+-e git://
No changes.
No changes.
@@ -10,6 +10,9 @@ sense without my narrative. However, for those not in the class, judicious use
of ``man`` and Google along with experimentation should make for an
interesting afternoon.
+All of the follow commands assume I'm running as root. Judicious use of
+``sudo`` would be required otherwise.
@@ -29,21 +32,24 @@ Hosts file for easier web-ing:: pycon-web1 pycon-web2 pycon-db1
1. Getting started
Bootstrap up the example app::
web1$ mkdir -p /home/web
- web1$ sudo aptitude update
- web1$ sudo aptitude install git-core python-dev python-setuptools postgresql-dev postgresql-client build-essential libpq-dev subversion
- web1$ sudo easy_install virtualenv
+ web1$ aptitude update
+ web1$ aptitude install git-core python-dev python-setuptools \
+ postgresql-dev postgresql-client build-essential \
+ libpq-dev subversion mercurial
+ web1$ easy_install virtualenv
web1$ git clone git://
web1$ cd /home/web
web1$ virtualenv myblog
web1$ cd myblog
web1$ source bin/activate
+ web1$ pip install -U pip
web1$ git clone git://
web1$ cd django-mingus/mingus
web1$ pip install -r stable-requirements.txt
@@ -59,22 +65,22 @@ Get ``http://pycon-web1:8000/`` - bing!
Install and configure Postgres::
- db1$ sudo aptitude update
- db1$ sudo aptitude install git-core postgresql
+ db1$ aptitude update
+ db1$ aptitude install git-core postgresql
db1$ mkdir -p /home/web
db1$ cd /home/web
db1$ git clone git://
db1$ cd /etc/postgresql/8.4/main/
- db1$ sudo invoke-rc.d postgresql-8.4 stop
- db1$ sudo mv postgresql.conf postgresql.conf.orig
- db1$ sudo mv pg_hba.conf pg_hba.conf.orig
- db1$ ln -s /home/web/django-deployment-workshop/postgresql/postgresql.conf
+ db1$ invoke-rc.d postgresql-8.4 stop
+ db1$ mv postgresql.conf postgresql.conf.orig
+ db1$ mv pg_hba.conf pg_hba.conf.orig
+ db1$ ln -s /home/web/django-deployment-workshop/postgresql/postgresql.conf .
db1$ ln -s /home/web/django-deployment-workshop/postgresql/pg_hba.conf .
- db1$ sudo invoke-rc.d postgresql-8.4 start
+ db1$ invoke-rc.d postgresql-8.4 start
And create users and database. Root user for convenience::
- db1$ sudo -u postgres createuser vagrant
+ db1$ sudo -u postgres createuser root
db1$ createuser mingus
db1$ createdb -O mingus mingus
@@ -89,6 +95,30 @@ Hit ``http://pycon-web1:8000/`` -- *boom*.
3. Application servers: mod_wsgi, gunicorn
+Install Apache and mod_wsgi, and zap away all the Ubuntu cruft::
+ web1$ aptitude install apache2 libapache2-mod-wsgi
+ web1$ cd /etc/apache2/
+ web1$ rm -rf apache2.conf conf.d/ httpd.conf magic mods-* sites-* ports.conf
+Add our config. Remember to make a python eggs dir (it should be writable by
+apache, but 777 is easier)::
+ web1$ ln -s /home/web/django-deployment-workshop/apache/apache2.conf .
+ web1$ ln -s /home/web/django-deployment-workshop/mingus-config/mingus.wsgi \
+ /home/web/myblog/mingus.wsgi
+ web1$ mkdir -m777 -p /var/www/.python-eggs
+ web1$ invoke-rc.d apache2 restart
+Hit ``http://pycon-web1/`` -- *boom*.
+Now try it with Gunicorn::
+ web1$ pip install gunicorn
+ web1$ cd /home/web/myblog/django-mingus/mingus
+ web1$ vim # INSTALLED_APPS += "gunicorn"
+ web1$ ./ run_gunicorn
4. Automation

0 comments on commit 4b33cf7

Please sign in to comment.