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