-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathmaster-slave.jps
112 lines (93 loc) · 3.45 KB
/
master-slave.jps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
type: update
id: mysql-master-slave-replication-cluster
name: MySQL/MariaDB/Percona Primary-Secondary Replication Database Cluster
description: 'DB Auto Clustering: 1 x Primary + N x Secondary'
baseUrl: https://raw.githubusercontent.com/sych74/mysql-cluster/JE-73464
success:
text: /texts/phpmyadmin-credentials.md
targetNodes: none
nodeGroupAlias:
${settings.nodeGroup}: sqldb
mixins:
- /scripts/common.yml
globals:
DB_USER: ${settings.db_user:user-[fn.random]}
DB_PASS: ${settings.db_pass:[fn.password(20)]}
onBeforeMigrate:
- isEnvRunning
- if (!${response.isEnvRunning}):
- stopEvent:
type: warning
message: "Please run the environment before migration, otherwise the database cluster will be broken."
onBeforeClone:
- isEnvRunning
- if (!${response.isEnvRunning}):
- stopEvent:
type: warning
message: "Please run the environment before cloning, otherwise the database cluster will be broken."
onAfterScaleOut[sqldb]:
- forEach(event.response.nodes):
- syncCustomConfig:
nodeIdFrom: ${nodes.sqldb.master.id}
nodeIdTo: ${@i.id}
- setupSlave: ${@i.id}
- addSlave: ${@i.id}
onAfterMigrate:
- script: delete MANIFEST.id; return {result:0, jps:MANIFEST};
- install: ${response.jps}
settings:
nodeGroup: ${settings.nodeGroup}
onAfterClone:
- script: delete MANIFEST.id; return {result:0, jps:MANIFEST};
- install: ${response.jps}
envName: ${event.response.env.envName}
settings:
nodeGroup: ${settings.nodeGroup}
onInstall:
- getReplicaUser
- addCustomConfig
- forEach(i:nodes.sqldb):
- if (${@i.ismaster}):
- setupMaster: ${@i.id}
- env.control.AddContainerEnvVars[sqldb]:
vars:
PRIMARY_IP: ${@i.address}
- else:
setupSlave: ${@i.id}
- forEach(i:nodes.sqldb):
- if (!${@i.ismaster}):
addSlave: ${@i.id}
actions:
setupMaster:
- cmd[${this}]: |-
wget ${baseUrl}/configs/master.cnf -O /etc/mysql/conf.d/master.cnf &>> /var/log/run.log
sed -i "s/server-id.*/server-id = ${this}/" /etc/mysql/conf.d/master.cnf
sed -i "s/report_host.*/report_host = node${this}/" /etc/mysql/conf.d/master.cnf
sed -i "/auto-increment/d" /etc/mysql/conf.d/master.cnf
- applyVersionConfiguration:
id: ${this}
conf_file: /etc/mysql/conf.d/master.cnf
- if (!${settings.clone:false}):
- setupUsers:
id: ${this}
- setNodeDisplayName[${this}]: Primary
setupSlave:
- cmd[${this}]: |-
wget ${baseUrl}/configs/slave.cnf -O /etc/mysql/conf.d/slave.cnf &>> /var/log/run.log
sed -i "s/server-id.*/server-id = ${this}/" /etc/mysql/conf.d/slave.cnf
sed -i "s/report_host.*/report_host = node${this}/" /etc/mysql/conf.d/slave.cnf
- applyVersionConfiguration:
id: ${this}
conf_file: /etc/mysql/conf.d/slave.cnf
- setNodeDisplayName[${this}]: Secondary
addSlave:
- env.control.GetContainerEnvVarsByGroup[sqldb]
- setGlobals:
PRIMARY_IP: ${response.object.PRIMARY_IP}
- if (/response/.test("${globals.PRIMARY_IP}")):
- setGlobals:
PRIMARY_IP: ${nodes.sqldb.master.address}
- cmd[${this}]: |-
curl --silent https://raw.githubusercontent.com/jelastic-jps/mysql-cluster/master/addons/recovery/scripts/db-recovery.sh > /tmp/db-recovery.sh;
bash /tmp/db-recovery.sh --scenario restore_secondary_from_primary --donor-ip ${globals.PRIMARY_IP};
user: root