From d7da9bc8ca96689c380130fb122ef1cc97b163f8 Mon Sep 17 00:00:00 2001 From: Josh Jameson Date: Wed, 30 Sep 2020 16:49:44 +0100 Subject: [PATCH] Added support for sockets and empty passwords (#44) * Add socket support (via PDNS_gmysql_socket) * Update docker-entrypoint.sh * Update docker-entrypoint.sh --- pdns/docker-entrypoint.sh | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/pdns/docker-entrypoint.sh b/pdns/docker-entrypoint.sh index f9512c8..e428059 100755 --- a/pdns/docker-entrypoint.sh +++ b/pdns/docker-entrypoint.sh @@ -7,7 +7,7 @@ set -euo pipefail : "${PDNS_gmysql_port:=${MYSQL_ENV_MYSQL_PORT:-3306}}" : "${PDNS_gmysql_user:=${MYSQL_ENV_MYSQL_USER:-root}}" if [ "${PDNS_gmysql_user}" = 'root' ]; then - : "${PDNS_gmysql_password:=$MYSQL_ENV_MYSQL_ROOT_PASSWORD}" + : "${PDNS_gmysql_password:=${MYSQL_ENV_MYSQL_ROOT_PASSWORD:-}}" fi : "${PDNS_gmysql_password:=${MYSQL_ENV_MYSQL_PASSWORD:-powerdns}}" : "${PDNS_gmysql_dbname:=${MYSQL_ENV_MYSQL_DATABASE:-powerdns}}" @@ -21,14 +21,28 @@ fi export PDNS_gmysql_host PDNS_gmysql_port PDNS_gmysql_user PDNS_gmysql_password PDNS_gmysql_dbname -# Initialize DB if needed -MYSQL_COMMAND="mysql -h ${PDNS_gmysql_host} -P ${PDNS_gmysql_port} -u ${PDNS_gmysql_user} -p${PDNS_gmysql_password}" +EXTRA="" +# Password Auth +if [ "${PDNS_gmysql_password}" != "" ]; then + EXTRA="${EXTRA} -p${PDNS_gmysql_password}" +fi + +# Allow socket connections +if [ "${PDNS_gmysql_socket}" != "" ]; then + export PDNS_gmysql_host="localhost" + EXTRA="${EXTRA} --socket=${PDNS_gmysql_socket}" +fi + +MYSQL_COMMAND="mysql -h ${PDNS_gmysql_host} -P ${PDNS_gmysql_port} -u ${PDNS_gmysql_user}${EXTRA}" + +# Wait for MySQL to respond until $MYSQL_COMMAND -e ';' ; do >&2 echo 'MySQL is unavailable - sleeping' sleep 3 done +# Initialize DB if needed if [ "${SKIP_DB_CREATE:-false}" != 'true' ]; then $MYSQL_COMMAND -e "CREATE DATABASE IF NOT EXISTS ${PDNS_gmysql_dbname}" fi