commit 3c5ce29f67305c0013307c90818f909c4f7192e1 Author: j <0x006A@0x2620.org> Date: Sun Sep 4 13:25:14 2011 +0200 inital project layout diff --git a/.bzrignore b/.bzrignore new file mode 100644 index 0000000..9e6e4a0 --- /dev/null +++ b/.bzrignore @@ -0,0 +1,9 @@ +bin +include +lib +src +build +dev.sqlite +secret.txt +local_settings.py +pip-log.txt diff --git a/README b/README new file mode 100644 index 0000000..91a574d --- /dev/null +++ b/README @@ -0,0 +1,23 @@ +oxbrowser + +Get: + bzr branch PUBLIC_URL oxbrowser + cd oxbrowser + virtualenv . + pip -E . install -r requirements.txt + +Develop: + create oxbrowser/local_settings.py + + cd oxbrowser + python manage.py shell + + python manage.py runserver + +Deploy: + create oxbrowser/local_settings.py + + create /etc/nginx/sites-availavle/sitename.conf + + create /etc/init/oxbrowser.conf + diff --git a/etc/init/oxbrowser.conf b/etc/init/oxbrowser.conf new file mode 100644 index 0000000..e66968d --- /dev/null +++ b/etc/init/oxbrowser.conf @@ -0,0 +1,20 @@ +# oxbrowser gunicorn daemon +# + +description "oxbrowser daemon" + +start on runlevel [2345] +stop on runlevel [!2345] +kill timeout 5 +respawn + +env VENV=/srv/oxbrowser +env USER=oxbrowser +env HOME=/home/oxbrowser + +script +test -e /var/log/oxbrowser || (mkdir -p /var/log/oxbrowser && chown $USER:$USER /var/log/oxbrowser) +test -e /var/run/oxbrowser || (mkdir -p /var/run/oxbrowser && chown $USER:$USER /var/run/oxbrowser) +cd $VENV/oxbrowser +exec /usr/bin/sudo -u $USER $VENV/bin/gunicorn_django --bind unix:/var/run/oxbrowser/gunicorn.sock --timeout 90 --log-level info --log-file /var/log/oxbrowser/oxbrowser.log --workers 5 $VENV/oxbrowser/settings.py +end script diff --git a/etc/nginx/sites-available/oxbrowser.conf b/etc/nginx/sites-available/oxbrowser.conf new file mode 100644 index 0000000..9647c2a --- /dev/null +++ b/etc/nginx/sites-available/oxbrowser.conf @@ -0,0 +1,52 @@ +upstream gunicorn_oxbrowser { + server unix:///var/run/oxbrowser/gunicorn.sock fail_timeout=0; +} +server { + listen 80 default; + #server_name pandora.example.com; + + access_log /var/log/nginx/oxbrowser.access.log; + error_log /var/log/nginx/oxbrowser.error.log; + + location /admin/media { + root /srv/oxbrowser/src/django/django/contrib; + autoindex on; + } + location /favicon.ico { + root /srv/oxbrowser/static; + } + + location /static/ { + root /srv/oxbrowser; + autoindex on; + } + location /data/ { + internal; + root /srv/oxbrowser; + } + + location / { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_read_timeout 90; #should be in sync with gunicorn timeout + proxy_connect_timeout 90; #should be in sync with gunicorn timeout + if (!-f $request_filename) { + proxy_pass http://gunicorn_oxbrowser; + #proxy_pass http://127.0.0.1:XXXX; + break; + } + client_max_body_size 32m; + } + + error_page 404 /404.html; + location /404.html { + root /srv/oxbrowser/static; + } + + # redirect server error pages to the static page /50x.html + error_page 500 502 503 504 /50x.html; + location /50x.html { + root /srv/oxbrowser/static; + } +} diff --git a/fabfile.py b/fabfile.py new file mode 100644 index 0000000..aa01398 --- /dev/null +++ b/fabfile.py @@ -0,0 +1,47 @@ +#this is a fabfile, use it with fab from http://fabfile.org/ +# +# initial setup: +# fab production setup +# +# deploy changes: +# fab production deploy +# + +from os.path import join +from fabric.api import run, local, sudo, put, env + +env.project_name = 'oxbrowser' + +def production(): + env.hosts = ['%(project_name)s@r-w-x.org'%env, ] + env.project_root = '/srv/%(project_name)s'%env + +def bzr_push(): + local('bzr push bzr+ssh://%(project_name)s@%(host)s%(project_root)s'%env) + +def bzr_update(): + run('cd %(project_root)s;bzr update'%env) + +def virtual_run(cmd, *a, **kw): + cmd = 'cd %s; source bin/activate; %s' % (env.project_root, cmd) + run(cmd, *a, **kw) + +def update_requirements(): + run('pip -E %(project_root)s install -r %(project_root)s/requirements.txt'%env) + +def setup(): + """ + Setup a fresh virtualenv + """ + local('bzr push --use-existing-dir bzr+ssh://%(project_name)s@%(host)s%(project_root)s'%env) + run('cd %(project_root)s; test -e .bzr/checkout || bzr checkout'%env) + run('virtualenv %(project_root)s'%env) + put(join('settings', '%(host)s.py'%env), join(env.project_root, env.project_name, 'local_settings.py')) + update_requirements() + +def deploy(): + bzr_push() + bzr_update() + virtual_run('python %(project_root)s/%(project_name)s/manage.py syncdb;python %(project_root)s/%(project_name)s/manage.py migrate'%env) + run('sudo %(project_root)s/reload.sh'%env) + diff --git a/oxbrowser/__init__.py b/oxbrowser/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/oxbrowser/manage.py b/oxbrowser/manage.py new file mode 100755 index 0000000..be99f25 --- /dev/null +++ b/oxbrowser/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os + +root_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__))) +os.chdir(root_dir) + +#using virtualenv's activate_this.py to reorder sys.path +activate_this = os.path.join(root_dir, '..', 'bin', 'activate_this.py') +if os.path.exists(activate_this): + execfile(activate_this, dict(__file__=activate_this)) + + +from django.core.management import execute_manager +try: + import settings # Assumed to be in the same directory. +except ImportError: + import sys + sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__) + sys.exit(1) + +if __name__ == "__main__": + execute_manager(settings) diff --git a/oxbrowser/settings.py b/oxbrowser/settings.py new file mode 100644 index 0000000..5f6f351 --- /dev/null +++ b/oxbrowser/settings.py @@ -0,0 +1,129 @@ +# -*- coding: utf-8 -*- +# vi:si:et:sw=4:sts=4:ts=4 +# Django settings for oxbrowser project. +import os +from os.path import join + +SITENAME = 'oxbrowser' + +PROJECT_ROOT = os.path.normpath(os.path.dirname(__file__)) + +DEBUG = True +TEMPLATE_DEBUG = DEBUG +JSON_DEBUG = False + +XSENDFILE = False + +ADMINS = ( + ('j', 'j@mailb.org'), +) + +DEFAULT_FROM_EMAIL='j@mailb.org' + +MANAGERS = ADMINS + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': 'dev.sqlite', + 'USER': '', + 'PASSWORD': '', + 'HOST': '', + 'PORT': '' + } +} + +#CACHE_BACKEND = 'memcached://127.0.0.1:11211/' + +# Local time zone for this installation. Choices can be found here: +# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name +# although not all choices may be available on all operating systems. +# If running in a Windows environment this must be set to the same as your +# system time zone. +TIME_ZONE = 'Europe/Berlin' +#TIME_ZONE = 'Asia/Kolkata' + +# Language code for this installation. All choices can be found here: +# http://www.i18nguy.com/unicode/language-identifiers.html +LANGUAGE_CODE = 'en-us' + +SITE_ID = 1 + +# If you set this to False, Django will make some optimizations so as not +# to load the internationalization machinery. +USE_I18N = True +APPEND_SLASH = False + +# Absolute path to the directory that holds media. +# Example: "/home/media/media.lawrence.com/" +MEDIA_ROOT = join(PROJECT_ROOT, 'media') +STATIC_ROOT = join(PROJECT_ROOT, 'static') + + +# URL that handles the media served from MEDIA_ROOT. Make sure to use a +# trailing slash if there is a path component (optional in other cases). +# Examples: "http://media.lawrence.com", "http://example.com/media/" +MEDIA_URL = '/media/' + +STATIC_URL = '/static/' + +# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a +# trailing slash. +# Examples: "http://foo.com/media/", "/media/". +ADMIN_MEDIA_PREFIX = '/admin/media/' + +# List of callables that know how to import templates from various sources. +TEMPLATE_LOADERS = ( + 'django.template.loaders.filesystem.load_template_source', + 'django.template.loaders.app_directories.load_template_source', + 'django.template.loaders.eggs.load_template_source', +) + +MIDDLEWARE_CLASSES = ( + 'django.middleware.common.CommonMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'ox.django.middleware.ExceptionMiddleware', +) + +ROOT_URLCONF = 'oxbrowser.urls' + +TEMPLATE_DIRS = ( + join(PROJECT_ROOT, 'templates'), +) + +INSTALLED_APPS = ( + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.sites', + 'django.contrib.admin', + 'django.contrib.humanize', + 'django_extensions', + #'south', + +) + + +#overwrite default settings with local settings +try: + from local_settings import * +except ImportError: + pass + +# Make this unique, creates random key first at first time. +try: + SECRET_KEY +except NameError: + SECRET_FILE = os.path.join(PROJECT_ROOT, 'secret.txt') + try: + SECRET_KEY = open(SECRET_FILE).read().strip() + except IOError: + try: + from random import choice + SECRET_KEY = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)]) + secret = file(SECRET_FILE, 'w') + secret.write(SECRET_KEY) + secret.close() + except IOError: + Exception('Please create a %s file with random characters to generate your secret key!' % SECRET_FILE) diff --git a/oxbrowser/urls.py b/oxbrowser/urls.py new file mode 100644 index 0000000..1f56b72 --- /dev/null +++ b/oxbrowser/urls.py @@ -0,0 +1,17 @@ +from django.conf.urls.defaults import patterns, include, url + +# Uncomment the next two lines to enable the admin: +# from django.contrib import admin +# admin.autodiscover() + +urlpatterns = patterns('', + # Examples: + # url(r'^$', 'oxbrowser.views.home', name='home'), + # url(r'^oxbrowser/', include('oxbrowser.foo.urls')), + + # Uncomment the admin/doc line below to enable admin documentation: + # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), + + # Uncomment the next line to enable the admin: + # url(r'^admin/', include(admin.site.urls)), +) diff --git a/reload.sh b/reload.sh new file mode 100755 index 0000000..ac211b0 --- /dev/null +++ b/reload.sh @@ -0,0 +1 @@ +kill -HUP `cat /var/run/oxbrowser.pid` diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..63cfb58 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +-e svn+http://code.djangoproject.com/svn/django/branches/releases/1.3.X#egg=django +-e bzr+http://code.0xdb.org/python-ox/#egg=python-ox +South +gunicorn +-e git://github.com/bit/django-extensions.git#egg=django_extensions