Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 28ed9c0

Browse files
authoredMar 18, 2019
Merge pull request #240 from jdeathe/issue/235
CLOSES #235: Adds improved basic initialisation SQL feature.
2 parents 48bfa2b + 0bbb0a0 commit 28ed9c0

File tree

14 files changed

+187
-34
lines changed

14 files changed

+187
-34
lines changed
 

‎CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ CentOS-6 6.10 x86_64 - MySQL 5.1.
2525
- Adds improvement to pull logic in systemd unit install template.
2626
- Adds `SSH_AUTOSTART_SUPERVISOR_STDOUT` with a value "false", disabling startup of `supervisor_stdout`.
2727
- Adds improved `healtchcheck`, `sshd-bootstrap` and `sshd-wrapper` scripts.
28+
- Adds `MYSQL_INIT_LIMIT` with a default value of "60" seconds.
29+
- Adds `MYSQL_INIT_SQL` with a default empty value "".
30+
- Deprecates `CUSTOM_MYSQL_INIT_SQL`, use `MYSQL_INIT_SQL` instead.
2831
- Removes use of `/etc/services-config` paths.
29-
- Removes code from configuration file `/etc/mysqld-bootstrap.conf`.
32+
- Removes use of `/etc/mysqld-bootstrap.conf`.
3033
- Removes X-Fleet section from etcd register template unit-file.
3134
- Removes the unused group element from the default container name.
3235
- Removes the node element from the default container name.

‎Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ RUN sed -i \
3131
-e "s~{{RELEASE_VERSION}}~${RELEASE_VERSION}~g" \
3232
/etc/systemd/system/centos-ssh-mysql@.service \
3333
&& chmod 600 \
34-
/etc/{my.cnf,mysqld-bootstrap.conf} \
34+
/etc/my.cnf \
3535
&& chmod 644 \
3636
/etc/supervisord.d/mysqld-{bootstrap,wrapper}.conf \
3737
&& chmod 700 \
@@ -44,6 +44,8 @@ EXPOSE 3306
4444
# ------------------------------------------------------------------------------
4545
ENV MYSQL_AUTOSTART_MYSQLD_BOOTSTRAP="true" \
4646
MYSQL_AUTOSTART_MYSQLD_WRAPPER="true" \
47+
MYSQL_INIT_LIMIT="60" \
48+
MYSQL_INIT_SQL="" \
4749
MYSQL_ROOT_PASSWORD="" \
4850
MYSQL_ROOT_PASSWORD_HASHED="false" \
4951
MYSQL_SUBNET="127.0.0.1" \

‎README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ $ docker logs mysql.1
5454

5555
On the first run, there will be additional output showing the initialisation SQL template and, before mysqld-bootstrap completes, the MySQL Details which shows the configured database, if applicable, and any associated user credentials.
5656

57-
![Docker Logs - MySQL Initialisation SQL Template](https://raw.github.com/jdeathe/centos-ssh-mysql/centos-6/images/docker-logs-mysqld-bootstrap-initialisation-sql.png)
58-
59-
![Docker Logs - MySQL Details](https://raw.github.com/jdeathe/centos-ssh-mysql/centos-6/images/docker-logs-mysqld-bootstrap-details.png)
57+
![Docker Logs - MySQL Bootstrap](https://raw.github.com/jdeathe/centos-ssh-mysql/centos-6/images/docker-logs-mysqld-bootstrap.png)
6058

6159
The MySQL table data is persistent across container restarts by setting the MySQL data directory `/var/lib/mysql` as a data volume. We didn't specify a name or docker_host path so Docker will give it a unique name and store it in `/var/lib/docker/volumes/`; to find out where the data is stored on the Docker host you can use `docker inspect`.
6260

@@ -289,6 +287,34 @@ It may be desirable to prevent the startup of the mysqld-bootstrap and/or mysqld
289287
...
290288
```
291289

290+
##### MYSQL_INIT_LIMIT
291+
292+
The default timeout for MySQL initialisation is 60 seconds. Use `MYSQL_INIT_LIMIT` to change this value when necessary.
293+
294+
```
295+
...
296+
--env "MYSQL_INIT_LIMIT=120" \
297+
...
298+
```
299+
300+
##### MYSQL_INIT_SQL
301+
302+
To add custom SQL to the MySQL intitialisation use `MYSQL_INIT_SQL` where the following placeholders are will get replaced with the appropriate values:
303+
304+
- `{{MYSQL_ROOT_PASSWORD}}`
305+
- `{{MYSQL_USER}}`
306+
- `{{MYSQL_USER_DATABASE}}`
307+
- `{{MYSQL_USER_HOST}}`
308+
- `{{MYSQL_USER_PASSWORD}}`
309+
310+
*Note:* The backtick "\`" character will need escaping as show in the example.
311+
312+
```
313+
...
314+
--env "MYSQL_INIT=CREATE DATABASE \`{{MYSQL_USER_DATABASE}}-1\`; GRANT ALL PRIVILEGES ON \`{{MYSQL_USER_DATABASE}}-%\`.* TO '{{MYSQL_USER}}'@'{{MYSQL_USER_HOST}}';" \
315+
...
316+
```
317+
292318
##### MYSQL_ROOT_PASSWORD
293319

294320
On first run the root user is created with an auto-generated password. If you require a specific password, `MYSQL_ROOT_PASSWORD` can be used when running the container.

‎default.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ define DOCKER_CONTAINER_PARAMETERS
4343
--restart $(DOCKER_RESTART_POLICY) \
4444
--env "MYSQL_AUTOSTART_MYSQLD_BOOTSTRAP=$(MYSQL_AUTOSTART_MYSQLD_BOOTSTRAP)" \
4545
--env "MYSQL_AUTOSTART_MYSQLD_WRAPPER=$(MYSQL_AUTOSTART_MYSQLD_WRAPPER)" \
46+
--env "MYSQL_INIT_LIMIT=$(MYSQL_INIT_LIMIT)" \
47+
--env "MYSQL_INIT_SQL=$(MYSQL_INIT_SQL)" \
4648
--env "MYSQL_ROOT_PASSWORD=$(MYSQL_ROOT_PASSWORD)" \
4749
--env "MYSQL_ROOT_PASSWORD_HASHED=$(MYSQL_ROOT_PASSWORD_HASHED)" \
4850
--env "MYSQL_SUBNET=$(MYSQL_SUBNET)" \

‎environment.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ STARTUP_TIME ?= 7
3434
# ------------------------------------------------------------------------------
3535
MYSQL_AUTOSTART_MYSQLD_BOOTSTRAP ?= true
3636
MYSQL_AUTOSTART_MYSQLD_WRAPPER ?= true
37+
MYSQL_INIT_LIMIT ?= 60
38+
MYSQL_INIT_SQL ?=
3739
MYSQL_ROOT_PASSWORD ?=
3840
MYSQL_ROOT_PASSWORD_HASHED ?= false
3941
MYSQL_SUBNET ?= 127.0.0.1
93.1 KB
Loading

‎src/etc/mysqld-bootstrap.conf

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎src/etc/systemd/system/centos-ssh-mysql@.service

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ Environment="DOCKER_PORT_MAP_TCP_3306=3306"
5858
Environment="DOCKER_USER=jdeathe"
5959
Environment="MYSQL_AUTOSTART_MYSQLD_BOOTSTRAP=true"
6060
Environment="MYSQL_AUTOSTART_MYSQLD_WRAPPER=true"
61+
Environment="MYSQL_INIT_LIMIT="
62+
Environment="MYSQL_INIT_SQL="
6163
Environment="MYSQL_ROOT_PASSWORD="
6264
Environment="MYSQL_ROOT_PASSWORD_HASHED=false"
6365
Environment="MYSQL_SUBNET=127.0.0.1"
@@ -123,6 +125,8 @@ ExecStart=/bin/bash -c \
123125
--name %p.%i \
124126
--env \"MYSQL_AUTOSTART_MYSQLD_BOOTSTRAP=${MYSQL_AUTOSTART_MYSQLD_BOOTSTRAP}\" \
125127
--env \"MYSQL_AUTOSTART_MYSQLD_WRAPPER=${MYSQL_AUTOSTART_MYSQLD_WRAPPER}\" \
128+
--env \"MYSQL_INIT_LIMIT=${MYSQL_INIT_LIMIT}\" \
129+
--env \"MYSQL_INIT_SQL=${MYSQL_INIT_SQL}\" \
126130
--env \"MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}\" \
127131
--env \"MYSQL_ROOT_PASSWORD_HASHED=${MYSQL_ROOT_PASSWORD_HASHED}\" \
128132
--env \"MYSQL_SUBNET=${MYSQL_SUBNET}\" \

‎src/opt/scmi/default.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ DOCKER_CONTAINER_PARAMETERS="--name ${DOCKER_NAME} \
4848
--restart ${DOCKER_RESTART_POLICY} \
4949
--env \"MYSQL_AUTOSTART_MYSQLD_BOOTSTRAP=${MYSQL_AUTOSTART_MYSQLD_BOOTSTRAP}\" \
5050
--env \"MYSQL_AUTOSTART_MYSQLD_WRAPPER=${MYSQL_AUTOSTART_MYSQLD_WRAPPER}\" \
51+
--env \"MYSQL_INIT_LIMIT=${MYSQL_INIT_LIMIT}\" \
52+
--env \"MYSQL_INIT_SQL=${MYSQL_INIT_SQL}\" \
5153
--env \"MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}\" \
5254
--env \"MYSQL_ROOT_PASSWORD_HASHED=${MYSQL_ROOT_PASSWORD_HASHED}\" \
5355
--env \"MYSQL_SUBNET=${MYSQL_SUBNET}\" \

‎src/opt/scmi/environment.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ REGISTER_UPDATE_INTERVAL="${REGISTER_UPDATE_INTERVAL:-95}"
3838
# ------------------------------------------------------------------------------
3939
MYSQL_AUTOSTART_MYSQLD_BOOTSTRAP="${MYSQL_AUTOSTART_MYSQLD_BOOTSTRAP:-true}"
4040
MYSQL_AUTOSTART_MYSQLD_WRAPPER="${MYSQL_AUTOSTART_MYSQLD_WRAPPER:-true}"
41+
MYSQL_INIT_LIMIT="${MYSQL_INIT_LIMIT:-60}"
42+
MYSQL_INIT_SQL="${MYSQL_INIT_SQL:-}"
4143
MYSQL_ROOT_PASSWORD="${MYSQL_ROOT_PASSWORD:-}"
4244
MYSQL_ROOT_PASSWORD_HASHED="${MYSQL_ROOT_PASSWORD_HASHED:-false}"
4345
MYSQL_SUBNET="${MYSQL_SUBNET:-127.0.0.1}"

‎src/opt/scmi/service-unit.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ readonly SERVICE_UNIT_ENVIRONMENT_KEYS="
88
DOCKER_PORT_MAP_TCP_3306
99
MYSQL_AUTOSTART_MYSQLD_BOOTSTRAP
1010
MYSQL_AUTOSTART_MYSQLD_WRAPPER
11+
MYSQL_INIT_LIMIT
12+
MYSQL_INIT_SQL
1113
MYSQL_ROOT_PASSWORD
1214
MYSQL_ROOT_PASSWORD_HASHED
1315
MYSQL_SUBNET

‎src/usr/sbin/mysqld-bootstrap

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env bash
22

3-
source /etc/mysqld-bootstrap.conf
4-
53
# Set MySQL client root user password
64
# - Prefer to store encrypted via mysql_config_editor.
75
# - Fallback to store as plaintext in secured file.
@@ -136,7 +134,8 @@ function __get_mysql_init_sql ()
136134
{
137135
local -r default_value="${1:-"-- Custom Initialisation SQL"}"
138136

139-
local value="${MYSQL_INIT_SQL}"
137+
# CUSTOM_MYSQL_INIT_SQL is deprecated, use MYSQL_INIT_SQL
138+
local value="${MYSQL_INIT_SQL:-"${CUSTOM_MYSQL_INIT_SQL}"}"
140139

141140
if ! __is_valid_mysql_init_sql "${value}"
142141
then
@@ -246,7 +245,7 @@ function __get_mysql_init_template ()
246245

247246
printf \
248247
-v template_user \
249-
-- "%s\nCREATE USER '%s'@'%s' \n%s '%s';" \
248+
-- "%s\nCREATE USER '%s'@'%s'\n%s '%s';" \
250249
"${template_user}" \
251250
"{{MYSQL_USER}}" \
252251
"{{MYSQL_USER_HOST}}" \
@@ -260,14 +259,20 @@ function __get_mysql_init_template ()
260259
then
261260
printf \
262261
-v template_privileges \
263-
-- "%s\nGRANT %s \nON \`%s\`.* \nTO '%s'@'%s';" \
262+
-- "%s\nGRANT %s\nON \`%s\`.*\nTO '%s'@'%s';" \
264263
"${template_privileges}" \
265264
"ALL PRIVILEGES" \
266265
"{{MYSQL_USER_DATABASE}}" \
267266
"{{MYSQL_USER}}" \
268267
"{{MYSQL_USER_HOST}}"
269268
fi
270269

270+
# Each statement must be on a single line and should not include comments.
271+
# Append a newline character to SQL line ending characters ";".
272+
init_sql="${init_sql//; /;}"
273+
init_sql="${init_sql//;/;$'\n'}"
274+
init_sql="${init_sql/%$'\n'}"
275+
271276
# Listen for the template and output as required
272277
if [[ ${compact} == false ]]
273278
then
@@ -312,8 +317,8 @@ function __get_mysql_init_template ()
312317
-- Custom Initialisation SQL end
313318
-- -----------------------------------------------------------------------------
314319
${template_privileges}
315-
GRANT ALL PRIVILEGES
316-
ON *.*
320+
GRANT ALL PRIVILEGES
321+
ON *.*
317322
TO 'root'@'localhost' IDENTIFIED BY '{{MYSQL_ROOT_PASSWORD}}' WITH GRANT OPTION;
318323
FLUSH PRIVILEGES;
319324
-- -----------------------------------------------------------------------------

‎src/usr/sbin/mysqld-wrapper

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
set -e
44

5-
source /etc/mysqld-bootstrap.conf
6-
75
function __is_valid_mysql_autostart_mysqld_bootstrap ()
86
{
97
local -r boolean_value='^(true|false)$'

0 commit comments

Comments
 (0)
This repository has been archived.