MySQL Service
The MySQL service is a more complex service image composed of four directories.
The contents of the the four directories are shown in the table below:
| Directory | Contents |
|---|---|
| bin/ | addDataSource configureDataSource† configureMySQL enstratus - backupDataSource† enstratus - check† enstratus - conf igure* enstratus-configureDataSource enstratus - dbgrant† enstratus - installds† enstratus-lock enstratus - start* enstratus - stop* mysql mysqlDump mysqlGrant mysqlStartReplication |
| cfg/ | master.cnf replicant.cnf |
| data | <empty> |
| log | <empty> |
Note: There are more directories than the required bin/ and cfg/ directory structure. Also, there are many more scripts than the required enstratus-configure, enstratus-start, and enstratus-stop. What has not changed is that the enstratus-configure script is the critical hook point for configuring the MySQL service image.
Items marked with a † are service scripts that are called by agent scripts.
An exhaustive explanation of the MySQL service image is beyond the scope of this document, but the functionality is the same in every service image. As an introduction to the functionality of the MySQL service image, let’s take a look at the enstratus-configure script for that service.
1 #!/usr/bin/python
2
3 import ConfigParser;
4 import sys;
5 import subprocess;
6
7 cfg = ConfigParser.ConfigParser();
8
9 cfg.read(sys.argv[2]);
10
11 userId = cfg.get(’enStratus’, ’userId’);
12 customerId = cfg.get(’enStratus’, ’customerId’);
13 role = ’master’
14 if cfg.has_option(’enStratus’, ’role’):
15 role = cfg.get(’enStratus’, ’role’);
16 serverId = cfg.get(’enStratus’, ’serverId’);
17 appId = cfg.get(’enStratus’, ’serviceId’);
18 port = cfg.get(’enStratus’, ’proxyPort’)
19
20 rootUser = cfg.get(’enStratus’, ’rootUser’);
21 rootPassword = cfg.get(’enStratus’, ’rootPassword’);
22 replicantUser = ""
23 if cfg.has_option(’enStratus’, ’replicationUser’):
24 replicantUser = cfg.get(’enStratus’, ’replicationUser’);
25 replicantPassword = ""
26 if cfg.has_option(’enStratus’, ’replicationPassword’):
27 replicantPassword = cfg.get(’enStratus’, ’replicationPassword’);
28
29 if role == ’replicant’:
30 masterHost = cfg.get(’enStratus’, ’masterHost’)
31 masterPort = cfg.get(’enStratus’, ’masterPort’)
32 input = open(’/mnt/services/%s/cfg/replicant.cnf’ % appId)
33 else:
34 input = open(’/mnt/services/%s/cfg/master.cnf’ % appId)
35
36 output = open(’/mnt/services/%s/cfg/my.cnf’ % appId, ’w’);
37
38 for line in input:
39 output.write(line.replace(’SERVERID’, serverId).replace(’APPID’,
40 appId).replace(’PORT’, port));
41 input.close();
42 output.close();
43
44 output = open(’/mnt/services/%s/cfg/mgr.cfg’ % appId, ’w’);
45 output.write(’[client]\n’);
46 output.write(’port=’ + port + ’\n’);
47 output.write(’socket=/var/run/mysqld/mysqld-’ + appId + ’.sock\n’);
48 output.write(’user=’ + rootUser + ’\n’);
49 output.write(’password=’ + rootPassword + ’\n’);
50 output.close();
51
52 subprocess.call([ ’sudo’, ’chmod’, ’600’, ’/mnt/services/%s/cfg/mgr.cfg’ %
53 appId]);
54
55 subprocess.call([’sudo’, ’/mnt/services/%s/bin/mysql’ % appId, appId, ’start’
56 ]);
57
58 subprocess.call([’/mnt/services/%s/bin/configureMySQL’ % appId, rootUser,
59 rootPassword ], cwd=’/mnt/services/%s’ % appId);
60
61 if role == ’replicant’: subprocess.call([
62 ’/mnt/services/%s/bin/mysqlStartReplication’ % appId, rootUser, rootPassword,
63 replicantUser, replicantPassword, masterHost, masterPort ])
64
65 subprocess.call([’sudo’, ’/mnt/services/%s/bin/mysql’ % appId, appId, ’stop’ ]);
The drop in point for this script is lines 7-9. Line 7 creates a new ConfigParser object and line 9 uses that object to read the second argument to the enstratus-configure script, which is the enstratus.cfg file.
Next, we'll look at Automation Features.
Updated: 08-01-2011: