13
cursor = get_db_cursor()
15
admin = os.path.basename(sys.argv[0]) == 'db-admin-relation-joined'
22
"grant replication client on *.* to `%s` identified by '%s'" % (
26
if slave and not admin:
29
"revoke all on `%s`.* from `%s`" % (
33
print "revoke failed, ignoring error"
35
"grant select on `%s`.* to `%s`" % (
41
"grant all privileges on *.* to `%s` identified by '%s'" % (
46
"grant all on `%s`.* to `%s` identified by '%s'" % (
51
hostname = subprocess.check_output(['unit-get','private-address']).strip()
53
print str(["relation-set",
54
"database=%s" % database_name,
56
"password=%s" % service_password,
60
# Create new database or touch slave.configured file
62
open(slave_configured_path,'w').close()
63
elif not broken and not admin:
64
# Find existing databases
65
cursor.execute("show databases")
66
databases = [i[0] for i in cursor.fetchall()]
67
if database_name in databases:
68
print "database exists already"
70
if not broken and not admin:
71
runsql("create database `%s` character set utf8" % database_name)
72
with open(database_name_file, 'w') as dbname:
73
dbname.write(database_name)
76
os.unlink(broken_path)
80
# Store new values in relation settings.
83
"database=%s" % database_name,
85
"password=%s" % service_password,