From b283617f517f47651d3be3bff6a598c0f3f81864 Mon Sep 17 00:00:00 2001 From: Dominik Dancs Date: Sat, 18 May 2024 18:50:42 +0200 Subject: [PATCH] Reworked entrypoint script --- docker-entrypoint.sh | 89 ++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 61 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 45a3848..b7c33c8 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,82 +1,49 @@ -#!/bin/sh +#! /bin/sh set -euo pipefail -# Configure mysql env vars -: "${PDNS_gmysql_host:=${MYSQL_ENV_MYSQL_HOST:-mysql}}" -: "${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:-}}" -fi -: "${PDNS_gmysql_password:=${MYSQL_ENV_MYSQL_PASSWORD:-powerdns}}" -: "${PDNS_gmysql_dbname:=${MYSQL_ENV_MYSQL_DATABASE:-powerdns}}" - -# use first part of node name as database name suffix -if [ "${NODE_NAME:-}" ]; then - NODE_NAME=$(echo ${NODE_NAME} | sed -e 's/\..*//' -e 's/-//') - PDNS_gmysql_dbname="${PDNS_gmysql_dbname}${NODE_NAME}" -fi +if [ "${PDNS_gmysql_host:-}" != "" ]; then + echo "Running migrations on the database..." + SQL_COMMAND="mysql -h ${PDNS_gmysql_host} -P ${PDNS_gmysql_port} -u ${PDNS_gmysql_user} -p${PDNS_gmysql_password} -D ${PDNS_gmysql_dbname}" -export PDNS_gmysql_host PDNS_gmysql_port PDNS_gmysql_user PDNS_gmysql_password PDNS_gmysql_dbname + # Fix DB schema + sed -i 's/CREATE TABLE/CREATE TABLE IF NOT EXISTS/g ; s/CREATE UNIQUE INDEX/CREATE UNIQUE INDEX IF NOT EXISTS/g ; s/CREATE INDEX/CREATE INDEX IF NOT EXISTS/g' /usr/share/doc/pdns/schema.mysql.sql -EXTRA="" + # Initialize DB if needed + $SQL_COMMAND &2 echo 'MySQL is unavailable - sleeping' - sleep 3 -done + # Fix DB schema + sed -i 's/CREATE TABLE/CREATE TABLE IF NOT EXISTS/g ; s/CREATE UNIQUE INDEX/CREATE UNIQUE INDEX IF NOT EXISTS/g ; s/CREATE INDEX/CREATE INDEX IF NOT EXISTS/g' /usr/share/doc/pdns/schema.pgsql.sql -# Initialize DB if needed -if [ "${SKIP_DB_CREATE:-false}" != 'true' ]; then - $MYSQL_COMMAND -e "CREATE DATABASE IF NOT EXISTS ${PDNS_gmysql_dbname}" -fi + # Initialize DB + $SQL_COMMAND /etc/pdns/pdns.conf +envtpl /etc/pdns/pdns.conf exec "$@"