Commits

Mikhail Korobov committed ce6b2b1

Move apache and nginx setup scripts to dedicated files

Comments (0)

Files changed (5)

+from fabric.api import run, env, settings
+from fabric.contrib.files import append
+
+from fab_deploy.utils import run_as, upload_config_template
+from fab_deploy.system import aptitude_install
+
+def touch(wsgi_file=None):
+    """ Reloads source code by touching the wsgi file """
+    if wsgi_file is None:
+        wsgi_file = env.conf['ENV_DIR']+'/var/wsgi/'+env.conf['INSTANCE_NAME']+'.py'
+    run('touch ' + wsgi_file)
+
+def apache_make_wsgi():
+    wsgi_dir = env.conf['ENV_DIR']+'/var/wsgi/'
+    run('mkdir -p ' + wsgi_dir)
+    file_name = env.conf['INSTANCE_NAME']+'.py'
+    upload_config_template('django_wsgi.py', wsgi_dir+file_name)
+
+@run_as('root')
+def apache_restart():
+    run('/etc/init.d/apache2 restart')
+
+# ==== installation ===
+
+@run_as('root')
+def apache_install():
+    aptitude_install('apache2 libapache2-mod-wsgi libapache2-mod-rpaf')
+    run('rm -f /etc/apache2/sites-enabled/default')
+    apache_setup_locale()
+
+@run_as('root')
+def apache_setup():
+    name = env.conf['INSTANCE_NAME']
+    upload_config_template('apache.config', '/etc/apache2/sites-available/%s' % name)
+    run("echo '' > /etc/apache2/ports.conf")
+    run('a2ensite %s' % name)
+
+@run_as('root')
+def apache_setup_locale():
+    append('/etc/apache2/envvars', ['export LANG="en_US.UTF-8"', 'export LC_ALL="en_US.UTF-8"'])
+    run('/etc/init.d/apache2 stop')
+    run('/etc/init.d/apache2 start')
+

fab_deploy/commands.py

 from datetime import datetime
 from fabric.api import run, env
+from fab_deploy.apache import touch
 from fab_deploy.utils import run_as, inside_project
 
-def touch():
-    """ Reloads source code by touching the wsgi file """
-    wsgi_file = env.conf['ENV_DIR']+'/var/wsgi/'+env.conf['INSTANCE_NAME']+'.py'
-    run('touch ' + wsgi_file)
-
 @inside_project
 def pip(commands=''):
     run('pip '+ commands)
     """ Deletes *.pyc files from project source dir """
     run("find . -name '*.pyc' -delete")
 
-@run_as('root')
-def restart_apache():
-    run('/etc/init.d/apache2 restart')
-
 from fab_deploy.utils import run_as, upload_config_template
 from fab_deploy.commands import touch, pip_install, pip_update, delete_pyc
 from fab_deploy.django_commands import compress, migrate, syncdb, test
-from fab_deploy.system import install_system_packages, setup_backports, apache_setup_locale, install_vcs
+from fab_deploy.system import install_system_packages, setup_backports, install_vcs
+from fab_deploy.apache import apache_setup, apache_install, touch
+from fab_deploy.nginx import nginx_setup, nginx_install
 
 def full_deploy():
     install_system_packages()
     make_virtualenv()
     make_clone()
     make_hgrc()
-    make_wsgi()
 
     pip_install('all')
 
 def make_hgrc():
     upload_config_template('hgrc', env.conf['SRC_DIR'] + '/.hg/hgrc')
 
-def make_wsgi():
-    wsgi_dir = env.conf['ENV_DIR']+'/var/wsgi/'
-    run('mkdir -p ' + wsgi_dir)
-    file_name = env.conf['INSTANCE_NAME']+'.py'
-    upload_config_template('django_wsgi.py', wsgi_dir+file_name)
+def setup_web_server():
+    apache_install()
+    nginx_install()
 
+    apache_setup()
+    nginx_setup()
 
 @run_as('root')
 def setup_web_server():
+from fabric.api import run, env, settings
+from fab_deploy.utils import run_as, upload_config_template
+from fab_deploy.system import aptitude_install
+
+@run_as('root')
+def nginx_install():
+    aptitude_install('nginx', 'lenny-backports')
+    run('rm -f /etc/nginx/sites-enabled/default')
+
+@run_as('root')
+def nginx_setup():
+    name = env.conf['INSTANCE_NAME']
+    upload_config_template('nginx.config', '/etc/nginx/sites-available/%s' % name)
+    with settings(warn_only=True):
+        run('ln -s /etc/nginx/sites-available/%s /etc/nginx/sites-enabled/%s' % (name, name))
+    run('/etc/init.d/nginx restart')
 #coding: utf-8
 from __future__ import with_statement
 from fabric.api import run, settings
-from fabric.contrib.files import append
 from fab_deploy.utils import run_as
 
 @run_as('root')
 def install_system_packages():
-    with settings(warn_only=True):
-        run('aptitude update')
-
     to_install = [
-        'apache2', 'python2.5', 'memcached', 'mutt', 'nginx',
+        'python2.5', 'memcached', 'mutt',
         'libjpeg-dev', 'libmysqlclient15-dev', 'zlib1g-dev',
         'build-essential', 'python-dev', 'python-setuptools',
-        'libapache2-mod-wsgi', 'python-profiler', 'libapache2-mod-rpaf',
-        'screen', 'locales-all', 'curl', 'libssl-dev', 'libcurl3-dev',
+        'python-profiler', 'screen', 'locales-all', 'curl',
+        'libssl-dev', 'libcurl3-dev',
     ] # + mysql-server
 
-    run('aptitude install -y %s' % " ".join(to_install))
+    aptitude_install(" ".join(to_install))
+
     run('easy_install -U pip')
     run('pip install -U virtualenv')
 
 
 @run_as('root')
+def aptitude_install(packages, repo=None, update=False):
+    if update:
+        with settings(warn_only=True):
+            run('aptitude update')
+    repo_arg = ('-t ' + repo) if repo else ''
+    run('aptitude install %s -y %s' % (repo_arg, packages,))
+
+
+@run_as('root')
 def setup_backports():
     run("echo 'deb http://backports.debian.org/debian-backports lenny-backports main contrib non-free' > /etc/apt/sources.list.d/backports.sources.list")
     with settings(warn_only=True):
 
 @run_as('root')
 def install_vcs():
-    run("aptitude -t lenny-backports install -y mercurial git-core")
-    run("aptitude install -y subversion bzr")
+    aptitude_install('mercurial git-core', 'lenny-backports')
+    aptitude_install('subversion bzr')
 
 
-@run_as('root')
-def apache_setup_locale():
-    append('/etc/apache2/envvars', ['export LANG="en_US.UTF-8"', 'export LC_ALL="en_US.UTF-8"'])
-    run('/etc/init.d/apache2 stop')
-    run('/etc/init.d/apache2 start')
-
 #@run_as('root')
 #def install_backup_system():
 #    run('aptitude install -y s3cmd ruby rubygems libxml2-dev libxslt-dev libopenssl-ruby')