Skip to content

Fetch client --socket value from config during init #266

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

Merged
merged 3 commits into from
Mar 24, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions 5.5/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ _datadir() {
"$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null | awk '$1 == "datadir" { print $2; exit }'
}

# For use with the client if user passes the --socket argument
_socket() {
"$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null | awk '$1 == "socket" { print $2; exit }'
}
Copy link
Member

Choose a reason for hiding this comment

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

Do you think there'd be any value in making something like a _get_config function to normalize these two? I guess _check_config is pretty similar too.

Something like this is what I was kind of thinking:

_get_config() {
	local conf="$1"; shift
	"$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null | awk '$1 == "'"$conf"'" { print $2; exit }'
}

datadir="$(_get_config 'datadir' "$@")"
socket="$(_get_config 'socket' "$@")"

(will defer to your decision, just wanted to throw the idea out there in case you hadn't considered it 👍)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I think that's a good idea, so I'll update the pr with it :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks to be working fine. I'll get the pr update up tomorrow once it's applied and tested for all versions.


# allow the container to be started with `--user`
if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then
_check_config "$@"
Expand Down Expand Up @@ -87,10 +92,11 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
mysql_install_db --datadir="$DATADIR" --rpm --basedir=/usr/local/mysql
echo 'Database initialized'

"$@" --skip-networking --basedir=/usr/local/mysql --socket=/var/run/mysqld/mysqld.sock &
SOCKET="$(_socket "$@")"
"$@" --skip-networking --basedir=/usr/local/mysql --socket="${SOCKET}" &
pid="$!"

mysql=( mysql --protocol=socket -uroot -hlocalhost --socket=/var/run/mysqld/mysqld.sock)
mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )

for i in {30..0}; do
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
Expand Down
10 changes: 8 additions & 2 deletions 5.6/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ _datadir() {
"$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null | awk '$1 == "datadir" { print $2; exit }'
}

# For use with the client if user passes the --socket argument
_socket() {
"$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null | awk '$1 == "socket" { print $2; exit }'
}

# allow the container to be started with `--user`
if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then
_check_config "$@"
Expand Down Expand Up @@ -87,10 +92,11 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
mysql_install_db --datadir="$DATADIR" --rpm --keep-my-cnf
echo 'Database initialized'

"$@" --skip-networking --socket=/var/run/mysqld/mysqld.sock &
SOCKET="$(_socket "$@")"
"$@" --skip-networking --socket="${SOCKET}" &
pid="$!"

mysql=( mysql --protocol=socket -uroot -hlocalhost --socket=/var/run/mysqld/mysqld.sock)
mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )

for i in {30..0}; do
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
Expand Down
10 changes: 8 additions & 2 deletions 5.7/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ _datadir() {
"$@" --verbose --help 2>/dev/null | awk '$1 == "datadir" { print $2; exit }'
}

# For use with the client if user passes the --socket argument
_socket() {
"$@" --verbose --help 2>/dev/null | awk '$1 == "socket" { print $2; exit }'
}

# allow the container to be started with `--user`
if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then
_check_config "$@"
Expand Down Expand Up @@ -94,10 +99,11 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
echo 'Certificates initialized'
fi

"$@" --skip-networking --socket=/var/run/mysqld/mysqld.sock &
SOCKET="$(_socket "$@")"
"$@" --skip-networking --socket="${SOCKET}" &
pid="$!"

mysql=( mysql --protocol=socket -uroot -hlocalhost --socket=/var/run/mysqld/mysqld.sock)
mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )

for i in {30..0}; do
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
Expand Down
10 changes: 8 additions & 2 deletions 8.0/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ _datadir() {
"$@" --verbose --help 2>/dev/null | awk '$1 == "datadir" { print $2; exit }'
}

# For use with the client if user passes the --socket argument
_socket() {
"$@" --verbose --help 2>/dev/null | awk '$1 == "socket" { print $2; exit }'
}

# allow the container to be started with `--user`
if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then
_check_config "$@"
Expand Down Expand Up @@ -94,10 +99,11 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
echo 'Certificates initialized'
fi

"$@" --skip-networking --socket=/var/run/mysqld/mysqld.sock &
SOCKET="$(_socket "$@")"
"$@" --skip-networking --socket="${SOCKET}" &
pid="$!"

mysql=( mysql --protocol=socket -uroot -hlocalhost --socket=/var/run/mysqld/mysqld.sock)
mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )

for i in {30..0}; do
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
Expand Down