1 # -*- coding: utf-8 -*-
3 # Copyright 2020 Arctos Labs Scandinavia AB
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
24 echo "Wait until $max_attempts seconds for MySQL mano Server ${db_host}:${db_port} "
25 while ! mysqladmin
ping -h"$db_host" -P"$db_port" --silent; do
27 if [ $attempt -ge $max_attempts ]; then
29 echo "Can not connect to database ${db_host}:${db_port} during $max_attempts sec"
39 function is_db_created
() {
46 if mysqlshow
-h"$db_host" -P"$db_port" -u"$db_user" -p"$db_pswd" |
grep -v Wildcard |
grep -q $db_name; then
47 echo "DB $db_name exists"
50 echo "DB $db_name does not exist"
55 if [[ $OSMPLA_SQL_DATABASE_URI == *'mysql'* ]]; then
56 DB_HOST
=$
(echo $OSMPLA_SQL_DATABASE_URI |
sed -r 's|^\w+://.+:.+@(.+):.*$|\1|')
57 DB_PORT
=$
(echo $OSMPLA_SQL_DATABASE_URI |
sed -r 's|^\w+://.*:([0-9]+).*$|\1|')
58 DB_USER
=$
(echo $OSMPLA_SQL_DATABASE_URI |
sed -r 's|^\w+://(.+):.+@.+$|\1|')
59 DB_PASSWORD
=$
(echo $OSMPLA_SQL_DATABASE_URI |
sed -r 's|^.+://.+:(.+)@.*$|\1|')
60 DB_NAME
=$
(echo $OSMPLA_SQL_DATABASE_URI |
sed -r 's|^\w+://.+:.+@.+:.*/(.+)$|\1|')
62 wait_db
"$DB_HOST" "$DB_PORT" ||
exit 1
64 is_db_created
"$DB_HOST" "$DB_PORT" "$DB_USER" "$DB_PASSWORD" "$DB_NAME" && DB_EXISTS
="Y"
66 if [ -z $DB_EXISTS ]; then
67 mysql
-h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASSWORD" --default_character_set utf8
-e "CREATE DATABASE $DB_NAME"