regluit/fabfile.py

80 lines
2.9 KiB
Python
Raw Normal View History

from fabric.api import run, local, env, cd
from regluit.sysadmin import aws
2012-04-09 21:22:38 +00:00
# allow us to use our ssh config files (e.g., ~/.ssh/config)
env.use_ssh_config = True
def rydev():
2012-04-09 21:22:38 +00:00
"""An example of using a function to define a host and use that definition in a command
to run:
fab rydev list_dir
"""
env.hosts = ['ec2-107-21-211-134.compute-1.amazonaws.com']
env.user = 'ubuntu'
2012-04-09 20:34:34 +00:00
def update_prod():
2012-04-09 21:22:38 +00:00
"""Updates the production serve by running /opt/regluit/deploy/update-prod"""
2012-04-09 20:34:34 +00:00
with cd("/opt/regluit"):
run("./deploy/update-prod")
def backup_db():
run("""TS=`date +"%Y-%m-%dT%H:%M:%S"`; /home/ubuntu/dump.sh | gzip > unglue.it.${TS}.sql.gz; scp ./unglue.it.${TS}.sql.gz b235656@hanjin.dreamhost.com: ; rm -f unglue.it.${TS}.sql.gz""")
def get_dump():
2012-04-09 21:22:38 +00:00
"""Dump the current db on remote server and scp it over to local machine.
Note: web1 has been hardcoded here to represent the name of the unglue.it server
"""
run("./dump.sh > unglue.it.sql ")
run("gzip -f unglue.it.sql")
local("scp web1:/home/ubuntu/unglue.it.sql.gz .")
local("gunzip -f unglue.it.sql.gz")
def build_prod_instance(ami_id='ami-a29943cb'):
"""Build a new instance to serve as server instance for unglue.it"""
# http://my.safaribooksonline.com/book/-/9781449308100/2dot-ec2-recipes/id2529379
# default ami-a29943cb' is Ubuntu 12.04 Precise EBS boot
def ssh_fingerprint():
"""display ssh fingerprint of /home/ubuntu/.ssh/id_rsa.pub on remote machine"""
run ("""ssh-keygen -l -f /home/ubuntu/.ssh/id_rsa.pub""")
def ssh_fingerprint2():
# http://stackoverflow.com/a/6682934/7782
import base64,hashlib
def lineToFingerprint(line):
key = base64.b64decode(line.strip().partition('ssh-rsa ')[2])
fp_plain = hashlib.md5(key).hexdigest()
return ':'.join(a+b for a,b in zip(fp_plain[::2], fp_plain[1::2]))
def public_key_from_private_key():
# ssh-keygen -y -f ~/.ssh/id_rsa
pass
def email_addresses():
"""list email addresses in unglue.it"""
with cd("/opt/regluit"):
run("""source ENV/bin/activate; echo "import django; print ', '.join([u.email for u in django.contrib.auth.models.User.objects.all() ]); quit()" | django-admin.py shell_plus --settings=regluit.settings.prod""")
def selenium():
2012-04-09 21:22:38 +00:00
"""setting up selenium to run in the background on RY's laptop"""
with cd('/Users/raymondyee/D/Document/Gluejar/Gluejar.github/regluit'):
local("java -jar test/selenium-server-standalone-2.20.0.jar > selenium-rc.log 2>&1 &")
def test():
2012-04-09 21:22:38 +00:00
"""run regluit tests locally"""
local("django-admin.py test core api frontend payment")
def list_dir():
2012-04-09 21:22:38 +00:00
"""A simple command to do a ls on /home/ubuntu/regluit """
code_dir = '/home/ubuntu/regluit'
with cd(code_dir):
run("ls")
def reboot():
"""Reboot from the command line -- USE WITH CARE"""
run("sudo shutdown -r now")
def host_type():
run('uname -s')