Saturday, September 28, 2013

Open Shift Django Basic

My 1 week research on various Paas ended at open shift.
I was a fan of heroku. Some pros of  openshift are 3 gears instead of 1 single dyno
and each gear have a 512MB memory, 1GB local storage than read only file system.
So a total of 1.5GB Ram and 3GB storage :)

Now coming to django to openshift

install rhc using

sudo gem install rhc

create an open shift app using

rhc app create APPNAME python-2.7 -s

-s is for auto scaling



uncomment the line install_requires=['Django==xxxxxxx
and change it according to the required django version if its 1.5.1


save and exit

git commit -am 'Initial commit'
git push

django app should be put in side wsgi

cd wsgi startproject PROJECTNAME

edit the file application

nano application

delete the contents and paste the new contents

import os, sys

sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi',

virtenv = os.environ['APPDIR'] + '/virtenv/'
os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python2.6/site-packages')
virtualenv = os.path.join(virtenv, 'bin/')

    execfile(virtualenv, dict(__file__=virtualenv))
except IOError:

# IMPORTANT: Put any additional includes below this line.  If placed above this
# line, it's possible required libraries won't be in your searchable path
from django.core.handlers import wsgi
application = wsgi.WSGIHandler() 

Now push the changes

cd ..
git add .
git commit -a -m "Project Creation"
git push 

Wait for push to finish,

One drawback of openshift is the time take to restart an app after a change is pushed.

Sunday, September 01, 2013

Django FastCgi with Nginx

When Launching a  django app, Configuring an nginx virtual host is the most tedious thing. I never can write a configuration with out fiddling with it for a day.

So I descided to write a script for it to auto manage it,

Clone my git hub repo

copy the to the app directory
specify the port for nginx as the first argument
eg :
$ 8011

What it does is:
1. Start django in fasctcgi
2. Generate an nginx virtual host configuration file
3. Reloads nginx
4. Happy :) ?