Skip to content

Commit

Permalink
Merge pull request codalab#304 from cpoulain/master
Browse files Browse the repository at this point in the history
Add task to create local instance of MySQL and a database on the web instance.
  • Loading branch information
cpoulain committed Jan 21, 2014
2 parents 6e9dec2 + e0f9a9c commit ea8dff4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion codalab/codalabtools/deploy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def getDatabaseUser(self):
return self._svc['database']['user']

def getDatabasePassword(self):
"""Gets the database password."""
"""Gets the password for the database user."""
return self._svc['database']['password']

def getDatabaseHost(self):
Expand All @@ -197,6 +197,10 @@ def getDatabasePort(self):
"""Gets the database port."""
return self._svc['database']['port']

def getDatabaseAdminPassword(self):
"""Gets the password for the database admin."""
return self._svc['database']['admin_password']

def getServicePublicStorageContainer(self):
"""Gets the name of the public Blob container for the service."""
return self._svc['storage']['public-container']
Expand Down
25 changes: 25 additions & 0 deletions codalab/codalabtools/deploy/fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,31 @@ def deploy_web():
run('python manage.py collectstatic --noinput')
sudo('ln -sf `pwd`/config/generated/nginx.conf /etc/nginx/sites-enabled/codalab.conf')

@roles('web')
@task
def install_mysql():
"""
Installs a local instance of MySQL of the web instance. This will only work
if the number of web instances is one.
"""
require('configuration')
if len(env.roledefs['web']) <> 1:
raise(Exception("Task install_mysql requires exactly one web instance."))

configuration = DeploymentConfig(env.cfg_label, env.cfg_path)
dba_password = configuration.getDatabaseAdminPassword()
db_name = configuration.getDatabaseName()
db_user = configuration.getDatabaseUser()
db_password = configuration.getDatabasePassword()

sudo('DEBIAN_FRONTEND=noninteractive apt-get -q -y install mysql-server')
sudo('mysqladmin -u root password {0}'.format(dba_password))

cmds = ["create database {0};".format(db_name),
"create user '{0}'@'localhost' IDENTIFIED BY '{1}';".format(db_user, db_password),
"GRANT ALL PRIVILEGES ON {0}.* TO '{1}'@'localhost' WITH GRANT OPTION;".format(db_name, db_user) ]
run('mysql --user=root --password={0} --execute="{1}"'.format(dba_password, " ".join(cmds)))

@roles('web')
@task
def supervisor():
Expand Down

0 comments on commit ea8dff4

Please sign in to comment.