Skip to content

Commit

Permalink
Make get_option() handle duplicate options in my_print_defaults output
Browse files Browse the repository at this point in the history
get_option() was added by docker-library#53 to extract `socket` and `pid-file` from
my_print_defaults. However if a custom mysql configuration file has been
added, my_print_defaults returns duplicates (it merely lists all options
specified in any config file and doesn't de-dupe). In these cases, `ret`
would equal `/var/run/mysqld/mysqld.sock /var/lib/mysql/mysql.sock`,
causing:
`/entrypoint.sh: line 9: [: /var/run/mysqld/mysqld.sock: binary operator expected`

As such, get_option() should just return the last matching option found
in the my_print_defaults output - which should correspond to the one in
the custom configuration file (rather than say the global default).

Fixes docker-library#74.
  • Loading branch information
Ed Morley committed Jun 11, 2015
1 parent f1b05ac commit f9fd52d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion 5.5/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ get_option () {
local section=$1
local option=$2
local default=$3
ret=$(my_print_defaults $section | grep '^--'${option}'=' | cut -d= -f2-)
# my_print_defaults can output duplicates, if an option exists both globally and in
# a custom config file. We pick the last occurence, which is from the custom config.
ret=$(my_print_defaults $section | grep '^--'${option}'=' | cut -d= -f2- | tail -n1)
[ -z $ret ] && ret=$default
echo $ret
}
Expand Down
4 changes: 3 additions & 1 deletion 5.6/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ get_option () {
local section=$1
local option=$2
local default=$3
ret=$(my_print_defaults $section | grep '^--'${option}'=' | cut -d= -f2-)
# my_print_defaults can output duplicates, if an option exists both globally and in
# a custom config file. We pick the last occurence, which is from the custom config.
ret=$(my_print_defaults $section | grep '^--'${option}'=' | cut -d= -f2- | tail -n1)
[ -z $ret ] && ret=$default
echo $ret
}
Expand Down
6 changes: 4 additions & 2 deletions 5.7/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ get_option () {
local section=$1
local option=$2
local default=$3
ret=$(my_print_defaults $section | grep '^--'${option}'=' | cut -d= -f2-)
# my_print_defaults can output duplicates, if an option exists both globally and in
# a custom config file. We pick the last occurence, which is from the custom config.
ret=$(my_print_defaults $section | grep '^--'${option}'=' | cut -d= -f2- | tail -n1)
[ -z $ret ] && ret=$default
echo $ret
}
Expand Down Expand Up @@ -77,6 +79,7 @@ if [ "$1" = 'mysqld' ]; then
echo 'FLUSH PRIVILEGES ;' >> "$tempSqlFile"

mysql -uroot < "$tempSqlFile"

rm -f "$tempSqlFile"
kill $(cat $PIDFILE)
for i in $(seq 30 -1 0); do
Expand All @@ -95,4 +98,3 @@ if [ "$1" = 'mysqld' ]; then
fi

exec "$@"

0 comments on commit f9fd52d

Please sign in to comment.