parent
b8e87c8836
commit
52e358782c
@ -6,47 +6,48 @@ set -e
|
|||||||
# treat everything except -- as exec cmd
|
# treat everything except -- as exec cmd
|
||||||
[ "${1:0:2}" != "--" ] && exec "$@"
|
[ "${1:0:2}" != "--" ] && exec "$@"
|
||||||
|
|
||||||
# Set MySQL Credentials in pdns.conf
|
|
||||||
if $MYSQL_AUTOCONF ; then
|
if $MYSQL_AUTOCONF ; then
|
||||||
|
# Set MySQL Credentials in pdns.conf
|
||||||
sed -r -i "s/^[# ]*gmysql-host=.*/gmysql-host=${MYSQL_HOST}/g" /etc/pdns/pdns.conf
|
sed -r -i "s/^[# ]*gmysql-host=.*/gmysql-host=${MYSQL_HOST}/g" /etc/pdns/pdns.conf
|
||||||
sed -r -i "s/^[# ]*gmysql-port=.*/gmysql-port=${MYSQL_PORT}/g" /etc/pdns/pdns.conf
|
sed -r -i "s/^[# ]*gmysql-port=.*/gmysql-port=${MYSQL_PORT}/g" /etc/pdns/pdns.conf
|
||||||
sed -r -i "s/^[# ]*gmysql-user=.*/gmysql-user=${MYSQL_USER}/g" /etc/pdns/pdns.conf
|
sed -r -i "s/^[# ]*gmysql-user=.*/gmysql-user=${MYSQL_USER}/g" /etc/pdns/pdns.conf
|
||||||
sed -r -i "s/^[# ]*gmysql-password=.*/gmysql-password=${MYSQL_PASS}/g" /etc/pdns/pdns.conf
|
sed -r -i "s/^[# ]*gmysql-password=.*/gmysql-password=${MYSQL_PASS}/g" /etc/pdns/pdns.conf
|
||||||
sed -r -i "s/^[# ]*gmysql-dbname=.*/gmysql-dbname=${MYSQL_DB}/g" /etc/pdns/pdns.conf
|
sed -r -i "s/^[# ]*gmysql-dbname=.*/gmysql-dbname=${MYSQL_DB}/g" /etc/pdns/pdns.conf
|
||||||
fi
|
|
||||||
|
|
||||||
|
MYSQLCMD="mysql --host='${MYSQL_HOST}' --user='${MYSQL_USER}' --password='${MYSQL_PASS}' -r -N"
|
||||||
|
|
||||||
MYSQLCMD="mysql -h $MYSQL_HOST -u $MYSQL_USER -p$MYSQL_PASS -r -N"
|
# wait for Database come ready
|
||||||
|
isDBup () {
|
||||||
# wait for Database come ready
|
|
||||||
isDBup () {
|
|
||||||
echo "SHOW STATUS" | $MYSQLCMD 1>/dev/null
|
echo "SHOW STATUS" | $MYSQLCMD 1>/dev/null
|
||||||
echo $?
|
echo $?
|
||||||
}
|
}
|
||||||
|
|
||||||
RETRY=10
|
RETRY=10
|
||||||
until [ `isDBup` -eq 0 ] || [ $RETRY -le 0 ] ; do
|
until [ `isDBup` -eq 0 ] || [ $RETRY -le 0 ] ; do
|
||||||
echo "Waiting for database to come up"
|
echo "Waiting for database to come up"
|
||||||
sleep 5
|
sleep 5
|
||||||
RETRY=$(expr $RETRY - 1)
|
RETRY=$(expr $RETRY - 1)
|
||||||
done
|
done
|
||||||
if [ $RETRY -le 0 ]; then
|
if [ $RETRY -le 0 ]; then
|
||||||
>&2 echo Error: Could not connect to Database on $MYSQL_HOST:$MYSQL_PORT
|
>&2 echo Error: Could not connect to Database on $MYSQL_HOST:$MYSQL_PORT
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# init database if necessary
|
# init database if necessary
|
||||||
echo "CREATE DATABASE IF NOT EXISTS $MYSQL_DB;" | $MYSQLCMD
|
echo "CREATE DATABASE IF NOT EXISTS $MYSQL_DB;" | $MYSQLCMD
|
||||||
MYSQLCMD="$MYSQLCMD $MYSQL_DB"
|
MYSQLCMD="$MYSQLCMD $MYSQL_DB"
|
||||||
|
|
||||||
if [ "$(echo "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = \"$MYSQL_DB\";" | $MYSQLCMD)" -le 1 ]; then
|
if [ "$(echo "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = \"$MYSQL_DB\";" | $MYSQLCMD)" -le 1 ]; then
|
||||||
echo Initializing Database
|
echo Initializing Database
|
||||||
cat /etc/pdns/schema.sql | $MYSQLCMD
|
cat /etc/pdns/schema.sql | $MYSQLCMD
|
||||||
|
fi
|
||||||
|
|
||||||
|
unset -v MYSQL_PASS
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Run pdns server
|
||||||
trap "pdns_control quit" SIGHUP SIGINT SIGTERM
|
trap "pdns_control quit" SIGHUP SIGINT SIGTERM
|
||||||
|
|
||||||
pdns_server "$@" &
|
pdns_server "$@" &
|
||||||
|
|
||||||
wait
|
wait
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user