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
29 echo "Wait until $max_attempts seconds for MySQL mano Server ${db_host}:${db_port} "
30 while ! mysqladmin
ping -h"$db_host" -P"$db_port" --silent; do
32 if [ $attempt -ge $max_attempts ]; then
34 echo "Can not connect to database ${db_host}:${db_port} during $max_attempts sec"
44 function is_db_created
() {
51 if mysqlshow
-h"$db_host" -P"$db_port" -u"$db_user" -p"$db_pswd" |
grep -v Wildcard |
grep -q $db_name; then
52 echo "DB $db_name exists"
55 echo "DB $db_name does not exist"
60 wait_db
"$DB_HOST" "$DB_PORT" ||
exit 1
62 is_db_created
"$DB_HOST" "$DB_PORT" "$ROOT_DB_USER" "$ROOT_DB_PASSWORD" "keystone" && DB_EXISTS
="Y"
64 if [ -z $DB_EXISTS ]; then
65 mysql
-h"$DB_HOST" -P"$DB_PORT" -u"$ROOT_DB_USER" -p"$ROOT_DB_PASSWORD" --default_character_set utf8
-e "CREATE DATABASE keystone"
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'@'localhost' IDENTIFIED BY '$KEYSTONE_DB_PASSWORD'"
67 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 if [ $
(mysql
-h"$DB_HOST" -P"$DB_PORT" -u"$ROOT_DB_USER" -p"$ROOT_DB_PASSWORD" --default_character_set utf8
-sse "SELECT COUNT(*) FROM keystone;") -gt 0 ]; then
70 echo "DB keystone is empty"
75 # Setting Keystone database connection
76 sed -i "721s%.*%connection = mysql+pymysql://keystone:$KEYSTONE_DB_PASSWORD@$DB_HOST:$DB_PORT/keystone%" /etc
/keystone
/keystone.conf
78 # Setting Keystone tokens
79 sed -i "2934s%.*%provider = fernet%" /etc
/keystone
/keystone.conf
81 # Populate Keystone database
82 if [ -z $DB_EXISTS ] ||
[ -z $DB_NOT_EMPTY ]; then
83 su
-s /bin
/sh
-c "keystone-manage db_sync" keystone
86 # Initialize Fernet key repositories
87 keystone-manage fernet_setup
--keystone-user keystone
--keystone-group keystone
88 keystone-manage credential_setup
--keystone-user keystone
--keystone-group keystone
90 # Bootstrap Keystone service
91 if [ -z $DB_EXISTS ] ||
[ -z $DB_NOT_EMPTY ]; then
92 keystone-manage bootstrap \
93 --bootstrap-username "$ADMIN_USERNAME" \
94 --bootstrap-password "$ADMIN_PASSWORD" \
95 --bootstrap-project "$ADMIN_PROJECT" \
96 --bootstrap-admin-url "http://$KEYSTONE_HOST:5000/v3/" \
97 --bootstrap-internal-url "http://$KEYSTONE_HOST:5000/v3/" \
98 --bootstrap-public-url "http://$KEYSTONE_HOST:5000/v3/" \
99 --bootstrap-region-id "$REGION_ID"
102 # Restart Apache Service
103 service apache2 restart
105 cat << EOF >> setup_env
106 export OS_PROJECT_DOMAIN_NAME=default
107 export OS_USER_DOMAIN_NAME=default
108 export OS_PROJECT_NAME=$ADMIN_PROJECT
109 export OS_USERNAME=$ADMIN_USERNAME
110 export OS_PASSWORD=$ADMIN_PASSWORD
111 export OS_AUTH_URL=http://$KEYSTONE_HOST:5000/v3
112 export OS_IDENTITY_API_VERSION=3
113 export OS_IMAGE_API_VERSION=2
119 if [ -z $DB_EXISTS ] ||
[ -z $DB_NOT_EMPTY ]; then
120 openstack user create
--domain default
--password "$SERVICE_PASSWORD" "$SERVICE_USERNAME"
121 openstack project create
--domain default
--description "Service Project" "$SERVICE_PROJECT"
122 openstack role add
--project "$SERVICE_PROJECT" --user "$SERVICE_USERNAME" admin
123 openstack role delete _member_
126 while ps
-ef |
grep -v grep |
grep -q apache2
131 # Only reaches this point if apache2 stops running
132 # When this happens exits with error code