Skip to content

Commit

Permalink
Bug#26643372 DOCKER IMAGE LOGS TO A FILE INSIDE THE CONTAINER WHICH I…
Browse files Browse the repository at this point in the history
…S DIFFICULT TO REACH

Add an environment variable MYSQL_LOG_STDOUT which, when set (any non-empty value), makes
the entrypoint script comment out the log-error line from the default config file.
This will make the command "docker logs container" output the MySQL server log

The flag has no effect on 8.0, where this is the default behavior
  • Loading branch information
ltangvald committed Aug 23, 2017
1 parent 572e0b6 commit 5b9e314
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ Changes in 1.1.1 (not released)
* Disable binlog for all entrypoint client commands (#87305)
This was previously only done only for the script to set the root password,
but should be done for all client commands, or group replication will fail
* Add flag for logging to stdout (#87458)
Setting -e MYSQL_LOG_STDOUT=true will make the server log to stdout, so the
server log is available through Docker's log interface.

Changes in 1.1.0 (2017-07-24)
* Fixed broken MYSQL_ONETIME_PASSWORD support (#86523)
The functionality wasn't correctly updated when the entrypoint script was
Expand Down
8 changes: 8 additions & 0 deletions genOracleLinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ TZINFO_WORKAROUND["5.6"]="sed 's/Local time zone must be set--see zic manual pag
TZINFO_WORKAROUND["5.7"]=""
TZINFO_WORKAROUND["8.0"]=""

# Logging to stdout makes server log available with the «docker logs command»
declare -A DEFAULT_LOG
DEFAULT_LOG["5.5"]=""
DEFAULT_LOG["5.6"]=""
DEFAULT_LOG["5.7"]=""
DEFAULT_LOG["8.0"]="stdout"

for VERSION in ${VERSIONS}
do
# Dockerfile
Expand All @@ -103,6 +110,7 @@ do
sed -i 's#%%INIT_STARTUP%%#'"${INIT_STARTUP[${VERSION}]}"'#g' tmpfile
sed -i 's#%%STARTUP_WAIT%%#'"${STARTUP_WAIT[${VERSION}]}"'#g' tmpfile
sed -i 's#%%SERVER_VERSION_FULL%%#'"${SERVER_VERSION_FULL[${VERSION}]}"'#g' tmpfile
sed -i 's#%%DEFAULT_LOG%%#'"${DEFAULT_LOG[${VERSION}]}"'#g' tmpfile
mv tmpfile ${VERSION}/docker-entrypoint.sh
chmod +x ${VERSION}/docker-entrypoint.sh

Expand Down
4 changes: 4 additions & 0 deletions template/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ if [ "$1" = 'mysqld' ]; then
DATADIR="$(_get_config 'datadir' "$@")"
SOCKET="$(_get_config 'socket' "$@")"

if [ -n "$MYSQL_LOG_STDOUT" ] || [ -n "%%DEFAULT_LOG%%" ]; then
sed -i 's/^log-error=/#&/' /etc/my.cnf
fi

if [ ! -d "$DATADIR/mysql" ]; then
if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
echo >&2 '[Entrypoint] ERROR: No password option specified for new database.'
Expand Down

0 comments on commit 5b9e314

Please sign in to comment.