1 # -*- coding: utf-8 -*-
3 # Copyright 2018 Whitestack, LLC
4 # *************************************************************
6 # This file is part of OSM Monitoring module
7 # All Rights Reserved to Whitestack, LLC
9 # Licensed under the Apache License, Version 2.0 (the "License"); you may
10 # not use this file except in compliance with the License. You may obtain
11 # a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18 # License for the specific language governing permissions and limitations
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact: glavado@whitestack.com
30 echo "Wait until $max_attempts seconds for MySQL mano Server ${db_host}:${db_port} "
31 while ! mysqladmin
ping -h"$db_host" -P"$db_port" --silent; do
33 if [ $attempt -ge $max_attempts ]; then
35 echo "Can not connect to database ${db_host}:${db_port} during $max_attempts sec"
45 function is_db_created
() {
52 if mysqlshow
-h"$db_host" -P"$db_port" -u"$db_user" -p"$db_pswd" |
grep -v Wildcard |
grep -q $db_name; then
53 echo "DB $db_name exists"
56 echo "DB $db_name does not exist"
61 if [[ $OSMMON_SQL_DATABASE_URI == *'mysql'* ]]; then
62 DB_HOST
=$
(echo $OSMMON_SQL_DATABASE_URI |
sed -r 's|^\w+://.+:.+@(.+):.*$|\1|')
63 DB_PORT
=$
(echo $OSMMON_SQL_DATABASE_URI |
sed -r 's|^\w+://.*:([0-9]+).*$|\1|')
64 DB_USER
=$
(echo $OSMMON_SQL_DATABASE_URI |
sed -r 's|^\w+://(.+):.+@.+$|\1|')
65 DB_PASSWORD
=$
(echo $OSMMON_SQL_DATABASE_URI |
sed -r 's|^.+://.+:(.+)@.*$|\1|')
66 DB_NAME
=$
(echo $OSMMON_SQL_DATABASE_URI |
sed -r 's|^\w+://.+:.+@.+:.*/(.+)$|\1|')
68 wait_db
"$DB_HOST" "$DB_PORT" ||
exit 1
70 is_db_created
"$DB_HOST" "$DB_PORT" "$DB_USER" "$DB_PASSWORD" "$DB_NAME" && DB_EXISTS
="Y"
72 if [ -z $DB_EXISTS ]; then
73 mysql
-h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASSWORD" --default_character_set utf8
-e "CREATE DATABASE $DB_NAME"