Commits

Mikhail Korobov committed 4677e55

Debian Squeeze support. Fix #1.

Comments (0)

Files changed (10)

         a bigger number if your software is not thread-safe (it will
         consume more memory though).
 
+.. attribute:: env.conf.OS
+
+    Server operating system name. Supported operating systems are
+    'lenny' and 'squeeze'. Default is 'lenny'.
+
+    .. warning::
+
+        Make sure this option is set properly. Deployment will fail with
+        incorrect value.
+
 .. attribute:: env.conf.HG_BRANCH
 
     Named hg branch that should be active on server. Default is "default".
 Prerequisites
 -------------
 
-1. Clean Debian Lenny (Debian Squeeze supported is planned) server or
-   VPS with root ssh access;
+1. Clean Debian Lenny or Debian Squeeze server/VPS with root ssh access;
 2. working ssh key authentication;
 3. django project stored in mercurial VCS.
 
             env.conf = dict(
                 DB_PASSWORD = 'password',
                 PROCESSES = 2,
+                # uncomment this for Debian Squeeze servers
+                # OS = 'squeeze',
             )
             update_env()
 
         my_site()
 
+   Make sure the :attr:`env.conf.OS` is correct (it is 'lenny' by default).
+
    In order to make things simple set :attr:`env.user` to your project name. It
    should be a valid python identifier. Don't worry if there is no such user
    on server, django-fab-deploy can create linux user and setup ssh
    You can adapt this file completely to your liking, but it should at least
    contain the root `toctree` directive.
 
-Welcome to django-fab-deploy's documentation!
-=============================================
+django-fab-deploy documentation
+===============================
 
 django-fab-deploy is a collection of `fabric`_ scripts for deploying and
 managing django projects on Debian servers.
 
 Server software:
 
-* the OS is Debian Lenny (support for Debian Squeeze is planned);
+* Debian Lenny and Debian Squeeze are supported;
 * the project is deployed with `Apache`_ + `mod_wsgi`_ for backend and
   `nginx`_ in front as a reverse proxy;
 

docs/reference.rst

 Reference
 =========
 
+.. note::
+
+    This is auto-generated API reference. Don't expect much from it.
+
+    [source] links are most useful.
+
 .. warning::
 
     django-fab-deploy is still at early stages of development and API may
 .. _silverlining: https://bitbucket.org/ianb/silverlining/src
 .. _woven: https://github.com/bretth/woven
 
-django-fab-deploy targets Debian, have smaller codebase (x5..x10 less sloc),
+django-fab-deploy targets Debian, have smaller codebase (about x5 less sloc),
 provides less features and thus is arguably easier to understand.

fab_deploy/config_templates/django_wsgi.py

 
 add_to_path([
      os.path.normpath('{{ ENV_DIR }}/lib/python2.5/site-packages'),
+     os.path.normpath('{{ ENV_DIR }}/lib/python2.6/site-packages'),
      os.path.normpath('{{ SRC_DIR }}' + '/..'),
      '{{ SRC_DIR }}'
 ])

fab_deploy/mysql.py

 from datetime import datetime
 from fabric.api import *
-from fab_deploy.utils import run_as, inside_project
+from fab_deploy.utils import run_as, inside_project, supports_only
 from fab_deploy.system import aptitude_install
 
 @run_as('root')
+@supports_only('lenny, squeeze')
 def mysql_install():
     """ Installs mysql. """
     if _mysql_is_installed():
     # see http://serverfault.com/questions/19367/scripted-install-of-mysql-on-ubuntu
     aptitude_install('debconf-utils')
     passwd=env.conf['DB_PASSWORD']
-    defaults = """mysql-server-5.0\tmysql-server/root_password_again\tpassword\t%s
-mysql-server-5.0\tmysql-server/root_password\tpassword\t%s""" % (passwd, passwd,)
-    run("echo '%s' | debconf-set-selections" % defaults)
+
+    mysql_versions = {'lenny': '5.0', 'squeeze': '5.1'}
+    version = mysql_versions[env.conf.OS]
+
+    debconf_defaults = [
+        "mysql-server-%s\tmysql-server/root_password_again\tpassword\t%s" % (version, passwd),
+        "mysql-server-%s\tmysql-server/root_password\tpassword\t%s" % (version, passwd),
+    ]
+    run("echo '%s' | debconf-set-selections" % "\n".join(debconf_defaults))
+
     warn('\n=========\nThe password for mysql "root" user will be set to "%s"\n=========\n' % passwd)
-
     aptitude_install('mysql-server')
 
 def _mysql_is_installed():

fab_deploy/nginx.py

 from fabric.api import run, env, settings
-from fab_deploy.utils import run_as, upload_config_template
+from fab_deploy.utils import run_as, upload_config_template, supports_only
 from fab_deploy.system import aptitude_install
 from fab_deploy.apache import _apache_setup_port
 
 @run_as('root')
+@supports_only('lenny, squeeze')
 def nginx_install():
     """ Installs nginx. """
-    aptitude_install('nginx', '-t lenny-backports')
+    options = {
+        'lenny': '-t lenny-backports',
+        'squeeze': '',
+    }
+    aptitude_install('nginx', options[env.conf.OS])
     run('rm -f /etc/nginx/sites-enabled/default')
 
 @run_as('root')

fab_deploy/system.py

 import os.path
 from fabric.api import run, settings, env, cd
 from fabric.contrib.files import append
-from fab_deploy.utils import run_as
+from fab_deploy.utils import run_as, supports_only
 
 def prepare_server():
     """ Prepares server: installs system packages. """
     install_common_software()
 
 @run_as('root')
+@supports_only('lenny, squeeze')
 def install_common_software():
     """ Installs common system packages. """
     to_install = [
-        'python2.5', 'build-essential', 'python-dev', 'python-setuptools',
-        'python-profiler', 'libjpeg-dev', 'libmysqlclient15-dev', 'zlib1g-dev',
+        'python', 'build-essential', 'python-dev', 'python-setuptools',
+        'python-profiler', 'libjpeg-dev', 'libmysqlclient-dev', 'zlib1g-dev',
         'libssl-dev', 'libcurl3-dev',
 
         'screen', 'locales-all', 'curl',
         'subversion',
     ]
 
-    aptitude_install('bzr', '--without-recommends')
     aptitude_install(" ".join(to_install))
 
-    # git and mercurial are outdated in stable Debian Lenny and don't work with
-    # some source repositories on github and bitbucket
-    aptitude_install('mercurial git-core', '-t lenny-backports')
+    # git and mercurial are outdated in stable Debian Lenny and
+    # don't work with some source repositories on github and bitbucket
+    vcs_options = {
+        'lenny': '-t lenny-backports',
+        'squeeze': '',
+    }
+    aptitude_install('mercurial git', vcs_options[env.conf.OS])
+    aptitude_install('bzr', '--without-recommends')
 
     run('easy_install -U pip')
     run('pip install -U virtualenv')
 
 
 @run_as('root')
+@supports_only('lenny, squeeze')
 def setup_backports():
     """ Adds backports repo to apt sources. """
-    run("echo 'deb http://backports.debian.org/debian-backports lenny-backports main contrib non-free' > /etc/apt/sources.list.d/backports.sources.list")
+    backports = {
+        'lenny': 'http://backports.debian.org/debian-backports lenny-backports main contrib non-free',
+        'squeeze': 'http://backports.debian.org/debian-backports squeeze-backports main contrib non-free',
+    }
+    run("echo 'deb %s' > /etc/apt/sources.list.d/backports.sources.list" % backports[env.conf.OS])
     with settings(warn_only=True):
         run('aptitude update')
 

fab_deploy/utils.py

 from fabric.api import *
 from fabric.state import _AttributeDict
 
+SUPPORTED_SYSTEMS = ['lenny', 'squeeze']
+
 def run_as(user):
     """
     Decorator. Runs fabric command as specified user. It is most useful to
         return inner
     return decorator
 
+def supports_only(supported_systems):
+    """ Safety decorator. Marks command as only supported for a set of
+    operating systems. Aborts execution if :attr:`env.conf.OS` is not in
+    list::
+
+        @supports_only('lenny, squeeze')
+        def my_command():
+            pass
+
+    """
+    systems = [s.strip().lower() for s in supported_systems.split(',')]
+    def decorator(func):
+        @wraps(func)
+        def inner(*args, **kwargs):
+            if env.conf.OS not in systems:
+                abort('%s is not supported. Supported operating systems: %s' % (
+                    env.conf.OS, supported_systems))
+            return func(*args, **kwargs)
+        return inner
+    return decorator
+
 def upload_config_template(name, to=None):
     if to is None:
         base_dir = env.conf['ENV_DIR'] + "/etc/"
         HOST = env.hosts[0],
         SERVER_NAME = env.hosts[0].split(':')[0],
         SERVER_ADMIN = 'example@example.com',
+        OS = 'lenny',
     )
     defaults.update(env.conf)
     env.conf = defaults
+    if env.conf.OS not in SUPPORTED_SYSTEMS:
+        abort('%s is not supported. Supported operating systems: %s' % (
+            env.conf.OS, ', '.join(SUPPORTED_SYSTEMS)
+        ))
 
 def virtualenv():
     """