2012-04-09 19:49:16 +00:00
|
|
|
from fabric.api import run, local, env, cd
|
2012-05-01 00:38:09 +00:00
|
|
|
from regluit.sysadmin import aws
|
2012-04-09 19:49:16 +00:00
|
|
|
|
2012-04-09 21:22:38 +00:00
|
|
|
# allow us to use our ssh config files (e.g., ~/.ssh/config)
|
2012-04-09 19:49:16 +00:00
|
|
|
env.use_ssh_config = True
|
|
|
|
|
2012-05-05 20:45:50 +00:00
|
|
|
DATA_BACKUP_ACCOUNT = 'b235656@hanjin.dreamhost.com'
|
|
|
|
|
2012-04-09 19:49:16 +00:00
|
|
|
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
|
|
|
|
"""
|
|
|
|
|
2012-04-09 19:49:16 +00:00
|
|
|
env.hosts = ['ec2-107-21-211-134.compute-1.amazonaws.com']
|
|
|
|
env.user = 'ubuntu'
|
|
|
|
|
2012-05-11 19:40:57 +00:00
|
|
|
def fps_key_local():
|
|
|
|
""" """
|
|
|
|
pass
|
|
|
|
|
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")
|
|
|
|
|
2012-05-05 20:45:50 +00:00
|
|
|
def backup_db(name='unglue.it', server=DATA_BACKUP_ACCOUNT):
|
|
|
|
"""backup database on unglue.it or please with name to server"""
|
|
|
|
run("""TS=`date +"%Y-%m-%dT%H:%M:%S"`; /home/ubuntu/dump.sh | gzip > {0}.${{TS}}.sql.gz; scp ./{0}.${{TS}}.sql.gz {1}: ; rm -f {0}.${{TS}}.sql.gz""".format(name, server))
|
|
|
|
|
|
|
|
def list_backups(name='unglue.it', server=DATA_BACKUP_ACCOUNT):
|
|
|
|
local("""echo "ls -lt {0}.*" | sftp {1}""".format(name, server))
|
2012-04-27 00:21:28 +00:00
|
|
|
|
2012-04-09 19:49:16 +00:00
|
|
|
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
|
|
|
|
"""
|
2012-04-09 19:49:16 +00:00
|
|
|
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")
|
2012-05-01 00:38:09 +00:00
|
|
|
|
2012-05-02 05:39:19 +00:00
|
|
|
def copy_dump_to_ry_dev():
|
|
|
|
"""Dump the current db on remote server and scp it over to ry-dev.
|
|
|
|
Note: web1 has been hardcoded here to represent the name of the unglue.it server
|
|
|
|
"""
|
|
|
|
run("./dump.sh > unglue.it.sql ")
|
|
|
|
run("scp unglue.it.sql ry-dev.dyndns.org:")
|
|
|
|
|
|
|
|
|
2012-05-01 00:38:09 +00:00
|
|
|
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
|
2012-05-02 05:39:19 +00:00
|
|
|
|
|
|
|
def ecdsa():
|
|
|
|
"""Calculate the host ECSDA host fingerprint http://bridge.grumpy-troll.org/2011/01/openssh.html """
|
|
|
|
run("""ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key.pub -l""")
|
2012-05-01 00:38:09 +00:00
|
|
|
|
|
|
|
def ssh_fingerprint():
|
2012-05-13 01:23:09 +00:00
|
|
|
"""display ssh fingerprint of /etc/ssh/ssh_host_rsa_key.pub on remote machine"""
|
|
|
|
run ("""ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub""")
|
2012-05-12 01:54:21 +00:00
|
|
|
|
|
|
|
def set_key_ry(name,value):
|
|
|
|
"""ry-dev is configured differently!"""
|
|
|
|
with cd("/home/ubuntu"):
|
|
|
|
run("""source /home/ubuntu/.virtualenvs/regluit/bin/activate; django-admin.py set_key {0} {1} --settings=regluit.settings.me""".format(name, value))
|
2012-05-01 00:38:09 +00:00
|
|
|
|
2012-05-10 01:02:59 +00:00
|
|
|
def set_key(name, value):
|
|
|
|
"""set encrypted key via the remote Django command -- works for web1, just, please"""
|
|
|
|
with cd("/opt/regluit"):
|
2012-05-15 17:24:43 +00:00
|
|
|
run("""source ENV/bin/activate; django-admin.py set_key {0} "{1}" --settings=regluit.settings.me""".format(name, value))
|
2012-05-10 01:02:59 +00:00
|
|
|
|
2012-05-01 00:38:09 +00:00
|
|
|
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
|
2012-04-27 19:01:53 +00:00
|
|
|
|
|
|
|
def email_addresses():
|
|
|
|
"""list email addresses in unglue.it"""
|
|
|
|
with cd("/opt/regluit"):
|
2012-05-10 01:02:59 +00:00
|
|
|
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.me""")
|
2012-04-27 19:01:53 +00:00
|
|
|
|
2012-04-09 19:49:16 +00:00
|
|
|
def selenium():
|
2012-04-09 21:22:38 +00:00
|
|
|
"""setting up selenium to run in the background on RY's laptop"""
|
2012-04-09 19:49:16 +00:00
|
|
|
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"""
|
2012-04-09 19:49:16 +00:00
|
|
|
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 """
|
2012-04-09 19:49:16 +00:00
|
|
|
code_dir = '/home/ubuntu/regluit'
|
|
|
|
with cd(code_dir):
|
|
|
|
run("ls")
|
|
|
|
|
2012-04-10 16:58:44 +00:00
|
|
|
def reboot():
|
|
|
|
"""Reboot from the command line -- USE WITH CARE"""
|
|
|
|
run("sudo shutdown -r now")
|
2012-04-09 19:49:16 +00:00
|
|
|
|
|
|
|
def host_type():
|
|
|
|
run('uname -s')
|