-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysqldb.bom
211 lines (172 loc) · 7.67 KB
/
mysqldb.bom
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
brooklyn.catalog:
id: mysqldb
name: MySQL Database
itemType: entity
description: Installs MySQL Database Server
items:
- id: mysql-base
name: Abstract MySQL Database Server
description: |
Defines common functionality of mysql-server and mysql-slave
item:
type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess
name: MySQL Server
brooklyn.parameters:
- name: root.password
description: Password for the root user
constraints:
- required
- name: login.user
description: Name of a user who may log in over remote connection. Required for master DB instance.
- name: login.password
description: Password for the login user. Required for master DB instance.
- name: mysql.port
type: port
description: Port of the mysql listener
default: 3306
- name: replication.password
description: Optional password for replication user. Replication is only configured if this is supplied.
type: string
- name: server.id
type: integer
description: MySQL 'server-id' value for replication. Only required if replication is configured.
- name: TODO.my.cnf.additions
description: TODO allow configuration of /etc/my.cnf - use augeas - or add a /root/.my.cnf
brooklyn.config:
provisioning.properties:
osFamily: ubuntu
shell.env:
ROOT_PASSWORD: $brooklyn:config("root.password")
REPLICATION_PASSWORD: $brooklyn:config("replication.password")
SERVER_ID: $brooklyn:config("server.id")
# note the install command ensures mysql is stopped, so derived types can do further config before start
install.command: |
cat > install-mysql.sh <<END
#!/usr/bin/env bash
set -e
# workaround for Ubuntu 16.04 problem with AppArmor denying access to a symlinked file
echo '/etc/mysql/** lr,' >> /etc/apparmor.d/local/usr.sbin.mysqld
sudo service apparmor restart
# install mysql 5.6
export DEBIAN_FRONTEND="noninteractive"
debconf-set-selections <<< "mysql-server mysql-server/root_password password ${ROOT_PASSWORD}"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${ROOT_PASSWORD}"
apt-get update
apt-get install -y software-properties-common
add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty universe'
apt-get update # update again to get contents of http://archive.ubuntu.com/ubuntu trusty universe
apt-get install -y libaio1 mysql-server-5.6 mysql-client-5.6 augeas-tools
update-rc.d mysql defaults
service mysql stop
END
chmod +x install-mysql.sh
sudo ./install-mysql.sh
sudo augtool <<EOF
rm /files/etc/mysql/my.cnf/target[ . = "mysqld" ]/bind-address
save
EOF
customize.command: |
fgrep '[mysqld]' /etc/mysql/my.cnf || sudo augtool <<EOF
set /files/etc/mysql/my.cnf/target[. = 'mysqld'] 'mysqld'
save
EOF
if [ -n "${REPLICATION_PASSWORD}" ] ; then
sudo augtool <<EOF
set /files/etc/mysql/my.cnf/target[ . = "mysqld" ]/lower_case_table_names "1"
set /files/etc/mysql/my.cnf/target[ . = "mysqld" ]/log-bin "mysql-bin"
set /files/etc/mysql/my.cnf/target[ . = "mysqld" ]/server-id "${SERVER_ID}"
set /files/etc/mysql/my.cnf/target[ . = "mysqld" ]/gtid_mode "ON"
set /files/etc/mysql/my.cnf/target[ . = "mysqld" ]/log-slave-updates "true"
set /files/etc/mysql/my.cnf/target[ . = "mysqld" ]/enforce-gtid-consistency "true"
set /files/etc/mysql/my.cnf/target[ . = "mysqld" ]/skip-slave-start "true"
save
EOF
fi
# see comment on install above, the derived types are required to start mysql
checkRunning.command: |
sudo service mysql status | egrep 'running|Active'
- id: mysql-server
name: MySQL Server
description: |
A MySQL Server installation
item:
type: mysql-base
brooklyn.config:
templates.runtime:
classpath://configure-mysql.sql : configure-mysql.sql
classpath://create-repl-user.sql : create-repl-user.sql
launch.command: |
sudo service mysql start
sudo mysql -u root -p${ROOT_PASSWORD} < configure-mysql.sql
if [ -n "${REPLICATION_PASSWORD}" ] ; then
sudo mysql -u root -p${ROOT_PASSWORD} <<< "RESET MASTER;"
sudo mysql -u root -p${ROOT_PASSWORD} < create-repl-user.sql
fi
- id: mysql-slave
name: MySQL Slave
description: |
Installs MySQL configured as a slave to an existing MySQL server, which must be a fresh installation
without any data so far.
item:
type: mysql-base
brooklyn.parameters:
- name: server
description: Brooklyn entity ID of the mysql-server entity
brooklyn.config:
master.host: $brooklyn:component(config("server")).attributeWhenReady("host.name")
master.user: repl
master.password: $brooklyn:component(config("server")).config("replication.password")
templates.runtime:
classpath://configure-mysql.sql : configure-mysql.sql
classpath://init-slave.sql : init-slave.sql
launch.command: |
sudo service mysql start
sudo mysql -u root -p${ROOT_PASSWORD} < configure-mysql.sql
sudo mysql -u root -p${ROOT_PASSWORD} < init-slave.sql
- id: mysql-database
name: MySQL Database
description: |
Installs a MySQL database on an exising MySQL server installation.
Supply a database name as configuration, and a schema creation script
either inline, or by providing a URL to fetch it from.
item:
type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess
name: MySQL Database
brooklyn.parameters:
- name: server
description: Brooklyn entity ID of the mysql-server entity
- name: databaseName
description: Name of the database to create
constraints:
- required
- name: schema.create.url
description: URL for database schema creation script
- name: schema.create.script
description: text of a database schema creation script
brooklyn.config:
shell.env:
ROOT_PASSWORD: $brooklyn:component(config("server")).config("root.password")
DATABASE_NAME: $brooklyn:config("databaseName")
SCHEMA_CREATE_URL: $brooklyn:config("schema.create.url")
SCHEMA_CREATE_SCRIPT: $brooklyn:config("schema.create.script")
templates.runtime:
classpath://create-database.sql : create-database.sql
customize.command: |
CREATE_SCHEMA_FILE=create-schema.sql
if [ -n "${SCHEMA_CREATE_URL}" ] ; then
echo fetching "${SCHEMA_CREATE_URL}"
curl -o ${CREATE_SCHEMA_FILE} ${SCHEMA_CREATE_URL}
elif [ -n "${SCHEMA_CREATE_SCRIPT}" ] ; then
printf "%s" "${SCHEMA_CREATE_SCRIPT}" > ${CREATE_SCHEMA_FILE}
else
>&2 echo Configuration must supply either "schema.create.url" or "schema.create.script"
exit 1
fi
launch.command: |
echo creating database ${DATABASE_NAME}
sudo mysql -u root -p${ROOT_PASSWORD} < create-database.sql
echo creating schema
sudo mysql -u root -p${ROOT_PASSWORD} ${DATABASE_NAME} < create-schema.sql
echo done
checkRunning.command: |
sudo mysql -u root -p${ROOT_PASSWORD} -e 'SHOW DATABASES' | grep ${DATABASE_NAME}