TT#68033 Migrate ngcp-update-db-schema from /etc/mysql/sipwise.cnf to /etc/mysql/sipwise_extra.cnf

Change-Id: I92577f18aa7439614b1cc349f9994566c008ff04
changes/85/34085/3
Alexander Lutay 6 years ago
parent f0603c28b2
commit 9606aa44bc

@ -39,19 +39,23 @@ if [ "${nodename}" = "unknown" ] ; then
fi fi
service mysql start || true service mysql start || true
. /etc/mysql/sipwise.cnf
. /etc/default/ngcp-roles . /etc/default/ngcp-roles
. /etc/default/ngcp-db . /etc/default/ngcp-db
if [ -z "${SIPWISE_DB_PASSWORD}" ] ; then declare -r SIPWISE_EXTRA_CNF="/etc/mysql/sipwise_extra.cnf"
echo 'Error: SIPWISE_DB_PASSWORD is unset (using /etc/mysql/sipwise.cnf).' >&2
if [ ! -f "${SIPWISE_EXTRA_CNF}" ]; then
echo "Error: missing DB credentials file '${SIPWISE_EXTRA_CNF}'." >&2
exit 1 exit 1
fi fi
declare -a MYSQL_OPTS=()
MYSQL_OPTS+=("--defaults-extra-file=${SIPWISE_EXTRA_CNF}")
# check connection with sipwise user # check connection with sipwise user
if ! mysql -usipwise -p"${SIPWISE_DB_PASSWORD}" -e 'SELECT 1;' 1>/dev/null 2>/dev/null ; then if ! mysql "${MYSQL_OPTS[@]}" -e 'SELECT 1;' 1>/dev/null 2>/dev/null ; then
echo 'Error: cant connect to local MySQL with sipwise user' >&2 echo "Error: can't connect to local MariaDB port 3306 using '${SIPWISE_EXTRA_CNF}'" >&2
exit 1 exit 1
fi fi
@ -59,7 +63,7 @@ fi
if [ -n "$AUTOMATED_INSTALL_MODE" ] ; then if [ -n "$AUTOMATED_INSTALL_MODE" ] ; then
echo "Running in automated installation mode, ignoring check for empty db_schema." echo "Running in automated installation mode, ignoring check for empty db_schema."
else else
if [ "$(mysql -usipwise -p"${SIPWISE_DB_PASSWORD}" -e 'select * from ngcp.db_schema;' 2>/dev/null)" = "" ] ; then if [ "$(mysql "${MYSQL_OPTS[@]}" -e 'select * from ngcp.db_schema;' 2>/dev/null)" = "" ] ; then
echo "=================================================================" echo "================================================================="
echo "Warning: the db_schema table of the ngcp database is empty." echo "Warning: the db_schema table of the ngcp database is empty."
echo "Are you sure you want to proceed with applying db-schema changes?" echo "Are you sure you want to proceed with applying db-schema changes?"
@ -75,16 +79,16 @@ else
fi fi
fi fi
if ! mysql -usipwise -p"${SIPWISE_DB_PASSWORD}" -e 'use ngcp;' 2>/dev/null ; then if ! mysql "${MYSQL_OPTS[@]}" -e 'use ngcp;' 2>/dev/null ; then
mysql -usipwise -p"${SIPWISE_DB_PASSWORD}" < /usr/share/ngcp-db-schema/db_scripts/init/0005_create_ngcp.up mysql "${MYSQL_OPTS[@]}" < /usr/share/ngcp-db-schema/db_scripts/init/0005_create_ngcp.up
fi fi
if ! mysql -usipwise -p"${SIPWISE_DB_PASSWORD}" -e 'use ngcp;' 2>/dev/null ; then if ! mysql "${MYSQL_OPTS[@]}" -e 'use ngcp;' 2>/dev/null ; then
echo 'Error: ngcp database does not exist.' >&2 echo 'Error: ngcp database does not exist.' >&2
exit 1 exit 1
fi fi
if ! mysql -usipwise -p"${SIPWISE_DB_PASSWORD}" ngcp -e 'describe db_schema' >/dev/null; then if ! mysql "${MYSQL_OPTS[@]}" ngcp -e 'describe db_schema' >/dev/null; then
echo 'Error: db_schema table does not exit.' >&2 echo 'Error: db_schema table does not exit.' >&2
exit 1 exit 1
fi fi
@ -128,7 +132,7 @@ apply_revision() {
revname="$(basename "$rev")" revname="$(basename "$rev")"
printf "Applying revision script %s: " "$rev" printf "Applying revision script %s: " "$rev"
if mysql -usipwise -p"${SIPWISE_DB_PASSWORD}" < "$rev" ; then if mysql "${MYSQL_OPTS[@]}" < "$rev" ; then
echo "done" echo "done"
else else
echo "failed. :(" >&2 echo "failed. :(" >&2
@ -136,7 +140,7 @@ apply_revision() {
exit 1 exit 1
fi fi
if mysql -usipwise -p"${SIPWISE_DB_PASSWORD}" ngcp -e "insert into db_schema values (0, '${revname}', '${nodename}', CURRENT_TIMESTAMP);" ; then if mysql "${MYSQL_OPTS[@]}" ngcp -e "insert into db_schema values (0, '${revname}', '${nodename}', CURRENT_TIMESTAMP);" ; then
verbose "Marked revision $rev as applied." verbose "Marked revision $rev as applied."
else else
echo "Error while executing DB commands using revision $rev for node $nodename" >&2 echo "Error while executing DB commands using revision $rev for node $nodename" >&2

Loading…
Cancel
Save