From: Ɓukasz Rekucki Date: Tue, 11 May 2010 10:51:33 +0000 (+0200) Subject: Alternative deployment. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/1089abd318e0a0541b6be4a410d913b94ee58a75?ds=inline Alternative deployment. --- diff --git a/deployment.py b/deployment.py new file mode 100644 index 000000000..b677fdf29 --- /dev/null +++ b/deployment.py @@ -0,0 +1,64 @@ +#!/srv/library/wolnelektury/pythonenv/bin/python +from __future__ import with_statement + +import shutil +import os +import sys + +from string import Template + +def render_template(source, dest, context={}): + print "Rendering template:", + with open(source, 'rb') as source_file: + t = Template(source_file.read()) + with open(dest, 'wb') as dest_file: + dest_file.write(t.safe_substitute(context)) + print "done." + +def restart_wsgi(): + print "Restarting wsgi application:", + os.system("touch %s" % WSGI_TARGET) + print "done." + +def update_application(): + print "Updating repository.", + os.system("cd %s; git pull" % PROJECT_ROOT) + print "Installing requirements" + os.system("pip install -r %s" % os.path.join(PROJECT_ROOT, 'requirements.txt')) + print "Installing local requirements" + os.system("pip install -r %s" % os.path.join(ROOT, 'etc', 'requirements.txt')) + print "done." + +ROOT = os.path.dirname(os.path.abspath(__file__)) + +PYTHON = os.path.join(ROOT, 'pythonenv', 'bin', 'python') +PYTHON_SITE = os.path.join(ROOT, 'pythonenv', 'lib', 'python2.6', 'site-packages') + +PROJECT_NAME = 'redakcja' +PROJECT_ROOT = os.path.join(ROOT, 'application') + +MEDIA_ROOT = os.path.join(ROOT, 'www', 'media') + +ADMIN_EMAIL = 'lrekucki@gmail.com' + +WSGI_TARGET = os.path.join(ROOT, 'www', 'wsgi', PROJECT_NAME + '.wsgi') +WSGI_DIR = os.path.dirname(WSGI_TARGET) + +WSGI_USER = PROJECT_NAME +WSGI_PROCESSES = 5 +WSGI_THREADS = 1 + +DOMAIN = 'lektury.staging.nowoczesnapolska.org.pl' + +# +# Load local configuration +# +sys.path = [ os.path.join(ROOT, 'etc') ] + sys.path + +from local_deployment import * + +if __name__ == '__main__': + update_application() + render_template(os.path.join(PROJECT_ROOT, PROJECT_NAME + '.wsgi.tmpl'), WSGI_TARGET, context=globals()) + render_template(os.path.join(PROJECT_ROOT, PROJECT_NAME + '.vhost.tmpl'), os.path.join(ROOT, 'etc', PROJECT_NAME + '.vhost'), context=globals()) + restart_wsgi() diff --git a/wolnelektury.vhost.tmpl b/wolnelektury.vhost.tmpl new file mode 100644 index 000000000..fbd21a9a1 --- /dev/null +++ b/wolnelektury.vhost.tmpl @@ -0,0 +1,25 @@ + + ServerName $DOMAIN + ServerAlias $DOMAIN_ALIASES + ServerAdmin $ADMIN_EMAIL + + WSGIDaemonProcess $PROJECT_NAME user=$WSGI_USER group=$WSGI_USER processes=$WSGI_PROCESSES threads=$WSGI_THREADS display-name=%{GROUP} + WSGIProcessGroup $PROJECT_NAME + + WSGIScriptAlias / $WSGI_TARGET + + Order allow,deny + allow from all + + + Alias /media $MEDIA_ROOT + + Options Indexes, FollowLinks + Order allow,deny + Allow from all + + + LogLevel warn + ErrorLog /var/log/apache2/$PROJECT_NAME/error.log + CustomLog /var/log/apache2/$PROJECT_NAME/access.log combined + diff --git a/wolnelektury.wsgi.tmpl b/wolnelektury.wsgi.tmpl new file mode 100644 index 000000000..6b772f34a --- /dev/null +++ b/wolnelektury.wsgi.tmpl @@ -0,0 +1,24 @@ +#!$PYTHON +import site +site.addsitedir('$PYTHON_SITE') + +import os +from os.path import abspath, dirname, join +import sys + +# Redirect sys.stdout to sys.stderr for bad libraries like geopy that use +# print statements for optional import exceptions. +sys.stdout = sys.stderr + +# Add apps and lib directories to PYTHONPATH +sys.path = [ + '$PROJECT_ROOT', + '$PROJECT_ROOT/lib', + '$PROJECT_ROOT/apps', +] + sys.path + +# Run Django +os.environ['DJANGO_SETTINGS_MODULE'] = '$PROJECT_NAME.settings' + +from django.core.handlers.wsgi import WSGIHandler +application = WSGIHandler()