Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from fabric.api import *
- APTITUDE_CACHE = set()
- PIP_CACHE = set()
- EASY_INSTALL_CACHE = set()
- def aptitude(package):
- aptitude_update()
- if package not in APTITUDE_CACHE:
- APTITUDE_CACHE.add(package)
- return sudo("aptitude -y install %s" % package)
- @runs_once
- def aptitude_update():
- sudo("aptitude update")
- def easy_install(package):
- aptitude("python-setuptools")
- if package not in EASY_INSTALL_CACHE:
- EASY_INSTALL_CACHE.add(package)
- sudo("easy_install %s" % package)
- def pip(package):
- easy_install("pip")
- if package not in PIP_CACHE:
- PIP_CACHE.add(package)
- return sudo("pip install %s" % package)
- def base():
- aptitude("emacs")
- aptitude("python-dev")
- aptitude("libjpeg-dev")
- aptitude("zlib1g-dev")
- aptitude("PIL")
- pip("virtualenv")
- aptitude("python-psycopg2")
- def nginx():
- base()
- aptitude("nginx")
- def apache():
- base()
- aptitude("apache2")
- aptitude("libapache2-mod-wsgi")
- def celery():
- base()
- def postgres():
- aptitude("emacs")
- aptitude("postgresql")
- password = prompt("Choose a new postgres root passord: ")
- sudo("psql -d template1 -c \"ALTER USER postgres with encrypted password '%s'\"" % password, user="postgres")
- #chanage pg_hba.conf (first line in perms): 'local all postgres md5 sameuser'
- sudo("/etc/init.d/postgresql-8.4 restart")
- def rabbitmq():
- aptitude("rabbitmq-server")
- def mq_setup():
- user = prompt("Enter rabbitMQ user: ")
- password = prompt("Enter rabbitMQ password: ")
- vhost = prompt("Enter rabbitMQ virtual host: ")
- sudo("rabbitmqctl add_user %s %s" % (user, password))
- sudo("rabbitmqctl add_vhost %s" % vhost)
- sudo("rabbitmqctl set_permissions -p %s %s \"\" \".*\" \".*\"" % (vhost, user))
- import os
- def file_insert_after_line(filename, search_line, insert_line, path=None):
- """
- Insert a line after the search_line
- matches search line with starts_with
- not great, but first iter works
- @@ change search_line to RE
- @@ if search_line not found, raise exception
- """
- if path is not None:
- filename = ''.join([path, filename])
- tmp = filename + "~"
- with open(tmp, 'w') as outfile:
- with open(filename, 'r') as infile:
- rows = iter(infile)
- for row in rows:
- if row.startswith(search_line):
- break
- outfile.write(row)
- outfile.write(row)
- outfile.write(insert_line + "\n")
- for row in rows:
- outfile.write(row)
- # @@ do i really have to do this again?
- with open(filename, 'w') as outfile:
- with open(tmp, 'r') as infile:
- rows = iter(infile)
- for row in rows:
- outfile.write(row)
- os.remove(tmp)
- def add_sudo():
- """
- promting user/pass for now, decide if we hard code, read from
- file, etc
- """
- user = prompt("Please enter a user: ")
- passwd = prompt("Please enter a password: ")
- run("useradd %s -d /home/%s -p %s" % user, user, password)
- file_insert_line('sudoers', '# User privilege specification', '%s ALL=(ALL) ALL' % user)
- def build_egg():
- local("python setup.py bdist_egg")
- put("dist/XXXX_XXXX.egg", "/remote/path/to/deploy")
- def create_repo(repo):
- with cd("/var/repo"):
- run("mkdir %s" % repo)
- with cd("%s" % repo):
- run("hg init .")
- sudo("find . -exec chown %s:devs {} \;" % env.user)
- sudo("find . -exec chmod g+s {} \;")
- sudo("find . -exec chmod g+w {} \;")
- def create_project(repo):
- create_repo(repo)
- local("hg clone ssh://%s@%s//repo/%s" % (env.user, env.host_string, repo))
- def tail(file):
- sudo("tail -f %s" % file)
- def reboot():
- sudo("reboot")
Add Comment
Please, Sign In to add comment