Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken SQL indents and run init.sh only once #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Fix broken SQL indents and run init.sh only once #2

wants to merge 8 commits into from

Conversation

db260179
Copy link

Hi Gadiener,

Your current master is broken due to incorrect indents when running the sql commands.

This breaks the replication process on startup.

Also the init.sh should be just run once on fresh install and not all the time.

Fix EOSQL indents as breaking the sql commands
Add check for already set MYSQL_GRANT_SLAVE_USER and password from environment variable
Copy the init.sh on first install then create a status file to ignore on further restarts
Copying init.sh to /usr/local/bin allows us to use this only once on a fresh install
@gadiener gadiener self-requested a review November 12, 2018 15:44
@gadiener gadiener self-assigned this Nov 12, 2018
@gadiener gadiener added the bug label Nov 12, 2018
@@ -1,6 +1,6 @@
FROM mariadb:10.3

COPY mariadb/init.sh /docker-entrypoint-initdb.d/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @db260179,

the mariadb image already runs the scripts inserted in /docker-entrypoint-initdb.d/ once, see: https://github.com/docker-library/mariadb/blob/44cfe68144976ce0ec135593ffe15c4bcca0dc6f/10.3/docker-entrypoint.sh#L80.

So you do not need to manually check in the entrypoint.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, so no need for that change.
I've added a commit to allow the master to confirm to the slave its ready to start. Although you have a 30 second count down it isn't that reliable and relying on the depends_on is not a good method especially on docker swarm

README.md Outdated
@@ -109,30 +98,3 @@ MYSQL_SLAVE_SKIP_ERRORS: "all" # (Optional) Default: 'OFF'
- Add `innodb-read-only` parameter (Service restart on first run is needed);
- Move `/etc/mysql/conf.d/master-slave.cnf` in other path (So the user can bind a volume to `/etc/mysql/conf.d/` for custom configuration);
- Permit replication on existing database.


## Contributing
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @db260179,

please leave this section in README file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are yes, sorry didn't realise I took it out

# On first install cp the init.sh
if [ ! -e "/docker-entrypoint-initdb.d/.init" ]; then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @db260179,

the docker-entrypoint-initdb.d directory isn't a volume, so docker will re-run this at every restart. The mariadb image already runs the scripts inserted in /docker-entrypoint-initdb.d/ once. So you don't need to check this here.

README.md Outdated
@@ -18,7 +15,7 @@ version: '3'

services:
db-master:
image: caffeina/mariadb-replication
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @db260179,

why force users to build the image when they can use the one already built?

@gadiener
Copy link
Owner

Hi @db260179,

thanks for your pull request. I gave you a little review, please answer me as soon as you can so I can merge your pull request.

Thanks for contributing,

Gabriele

No need to for the .init file as the mariadb container only runs on first run from the /docker-entrypoint-initdb.d
But we need to check if the init.sh exists as we are not assuming that a user might mount the /docker-entrypoint-initdb.d as a volume
The status folder will be used to when master is done and the slave is ready to proceed.
By adding a status function in the init.sh it allows the master to finish its tasks first before the slave can start
Unintentional commit change revert back
Create a /status folder so that the master can create a status file once finished
This allows the slave to only start once the master is ready.
Copy link
Author

@db260179 db260179 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope this helps and taken in account your comments
David

README.md Outdated
@@ -109,30 +98,3 @@ MYSQL_SLAVE_SKIP_ERRORS: "all" # (Optional) Default: 'OFF'
- Add `innodb-read-only` parameter (Service restart on first run is needed);
- Move `/etc/mysql/conf.d/master-slave.cnf` in other path (So the user can bind a volume to `/etc/mysql/conf.d/` for custom configuration);
- Permit replication on existing database.


## Contributing
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are yes, sorry didn't realise I took it out

@@ -1,6 +1,6 @@
FROM mariadb:10.3

COPY mariadb/init.sh /docker-entrypoint-initdb.d/
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, so no need for that change.
I've added a commit to allow the master to confirm to the slave its ready to start. Although you have a 30 second count down it isn't that reliable and relying on the depends_on is not a good method especially on docker swarm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants