3 # Copyright 2018 Whitestack, LLC
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License. You may obtain
7 # 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, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
17 # For those usages not covered by the Apache License, Version 2.0 please
18 # contact: esousa@whitestack.com or glavado@whitestack.com
28 echo "Wait until $max_attempts seconds for MySQL mano Server ${db_host}:${db_port} "
29 while ! mysqladmin
ping -h"$db_host" -P"$db_port" --silent; do
31 if [ $attempt -ge $max_attempts ]; then
33 echo "Can not connect to database ${db_host}:${db_port} during $max_attempts sec"
43 function is_db_created
() {
50 if mysqlshow
-h"$db_host" -P"$db_port" -u"$db_user" -p"$db_pswd" |
grep -v Wildcard |
grep -q $db_name; then
51 echo "DB $db_name exists"
54 echo "DB $db_name does not exist"
59 wait_db
"$DB_HOST" "$DB_PORT" ||
exit 1
61 is_db_created
"$DB_HOST" "$DB_PORT" "$ROOT_DB_USER" "$ROOT_DB_PASSWORD" "keystone" && DB_EXISTS
="Y"
63 if [ -z $DB_EXISTS ]; then
64 mysql
-h"$DB_HOST" -P"$DB_PORT" -u"$ROOT_DB_USER" -p"$ROOT_DB_PASSWORD" --default_character_set utf8
-e "CREATE DATABASE keystone"
65 mysql
-h"$DB_HOST" -P"$DB_PORT" -u"$ROOT_DB_USER" -p"$ROOT_DB_PASSWORD" --default_character_set utf8
-e "GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' IDENTIFIED BY '$KEYSTONE_DB_PASSWORD'"
66 mysql
-h"$DB_HOST" -P"$DB_PORT" -u"$ROOT_DB_USER" -p"$ROOT_DB_PASSWORD" --default_character_set utf8
-e "GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' IDENTIFIED BY '$KEYSTONE_DB_PASSWORD'"
69 # Setting Keystone database connection
70 sed -i "721s%.*%connection = mysql+pymysql://keystone:$KEYSTONE_DB_PASSWORD@$DB_HOST:$DB_PORT/keystone%" /etc
/keystone
/keystone.conf
72 # Setting Keystone tokens
73 sed -i "2934s%.*%provider = fernet%" /etc
/keystone
/keystone.conf
75 # Populate Keystone database
76 if [ -z $DB_EXISTS ]; then
77 su
-s /bin
/sh
-c "keystone-manage db_sync" keystone
80 # Initialize Fernet key repositories
81 keystone-manage fernet_setup
--keystone-user keystone
--keystone-group keystone
82 keystone-manage credential_setup
--keystone-user keystone
--keystone-group keystone
84 # Bootstrap Keystone service
85 if [ -z $DB_EXISTS ]; then
86 keystone-manage bootstrap
--bootstrap-password "$ADMIN_PASSWORD" \
87 --bootstrap-admin-url http
://keystone
:5000/v
3/ \
88 --bootstrap-internal-url http
://keystone
:5000/v
3/ \
89 --bootstrap-public-url http
://keystone
:5000/v
3/ \
90 --bootstrap-region-id RegionOne
93 # Restart Apache Service
94 service apache2 restart
96 cat << EOF >> setup_env
97 export OS_PROJECT_DOMAIN_NAME=default
98 export OS_USER_DOMAIN_NAME=default
99 export OS_PROJECT_NAME=admin
100 export OS_USERNAME=admin
101 export OS_PASSWORD=$ADMIN_PASSWORD
102 export OS_AUTH_URL=http://keystone:5000/v3
103 export OS_IDENTITY_API_VERSION=3
104 export OS_IMAGE_API_VERSION=2
110 if [ -z $DB_EXISTS ]; then
111 openstack user create
--domain default
--password "$NBI_PASSWORD" nbi
112 openstack project create
--domain default
--description "Service Project" service
113 openstack role add
--project service
--user nbi admin
116 while ps
-ef |
grep -v grep |
grep -q apache2
121 # Only reaches this point if apache2 stops running
122 # When this happens exits with error code