Skip to content

Commit

Permalink
Template: Store root password in file
Browse files Browse the repository at this point in the history
Storing the password in a file lets us use defaults-extra-file option so we don't
put it on the command line
  • Loading branch information
ltangvald authored and yosifkit committed Sep 18, 2019
1 parent a8aa1cf commit ea73775
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion .template.Debian/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,16 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
FLUSH PRIVILEGES ;
EOSQL

# Store the password in a file so we don't use it on the command line
install -d -m0700 /tmp/mysql-files
PASSFILE=$(mktemp /tmp/mysql-files/XXXXXXXXXX)
install /dev/null -m0600 "${PASSFILE}"
if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then
mysql+=( -p"${MYSQL_ROOT_PASSWORD}" )
cat >"${PASSFILE}" <<EOF
[client]
password="${MYSQL_ROOT_PASSWORD}"
EOF
mysql+=( --defaults-extra-file="${PASSFILE}" )
fi

file_env 'MYSQL_DATABASE'
Expand Down Expand Up @@ -232,6 +240,8 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
_note "Stopping server"
_stop_server $pid
_note "Server stopped"
rm -f "${PASSFILE}"
unset PASSFILE
echo
_note "MySQL init process done. Ready for start up."
echo
Expand Down

0 comments on commit ea73775

Please sign in to comment.