10 echo "Wait until $max_attempts seconds for MySQL mano Server ${db_host}:${db_port} "
11 while ! mysqladmin
ping -h"$db_host" -P"$db_port" --silent; do
13 if [ $attempt -ge $max_attempts ]; then
15 echo "Can not connect to database ${db_host}:${db_port} during $max_attempts sec"
25 function is_db_created
() {
32 if mysqlshow
-h"$db_host" -P"$db_port" -u"$db_user" -p"$db_pswd" |
grep -v Wildcard |
grep -q $db_name; then
33 echo "DB $db_name exists"
36 echo "DB $db_name does not exist"
41 wait_db
"$DB_HOST" "$DB_PORT" ||
exit 1
43 is_db_created
"$DB_HOST" "$DB_PORT" "$ROOT_DB_USER" "$ROOT_DB_PASSWORD" "keystone" && DB_EXISTS
="Y"
45 if [ -z $DB_EXISTS ]; then
46 mysql
-h"$DB_HOST" -P"$DB_PORT" -u"$ROOT_DB_USER" -p"$ROOT_DB_PASSWORD" --default_character_set utf8
-e "CREATE DATABASE keystone"
47 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'"
48 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'"
51 # Setting Keystone database connection
52 sed -i "721s%.*%connection = mysql+pymysql://keystone:$KEYSTONE_DB_PASSWORD@$DB_HOST:$DB_PORT/keystone%" /etc
/keystone
/keystone.conf
54 # Setting Keystone tokens
55 sed -i "2934s%.*%provider = fernet%" /etc
/keystone
/keystone.conf
57 # Populate Keystone database
58 if [ -z $DB_EXISTS ]; then
59 su
-s /bin
/sh
-c "keystone-manage db_sync" keystone
62 # Initialize Fernet key repositories
63 keystone-manage fernet_setup
--keystone-user keystone
--keystone-group keystone
64 keystone-manage credential_setup
--keystone-user keystone
--keystone-group keystone
66 # Bootstrap Keystone service
67 if [ -z $DB_EXISTS ]; then
68 keystone-manage bootstrap
--bootstrap-password "$ADMIN_PASSWORD" \
69 --bootstrap-admin-url http
://keystone
:5000/v
3/ \
70 --bootstrap-internal-url http
://keystone
:5000/v
3/ \
71 --bootstrap-public-url http
://keystone
:5000/v
3/ \
72 --bootstrap-region-id RegionOne
75 # Restart Apache Service
76 service apache2 restart
78 cat << EOF >> setup_env
79 export OS_PROJECT_DOMAIN_NAME=default
80 export OS_USER_DOMAIN_NAME=default
81 export OS_PROJECT_NAME=admin
82 export OS_USERNAME=admin
83 export OS_PASSWORD=$ADMIN_PASSWORD
84 export OS_AUTH_URL=http://keystone:5000/v3
85 export OS_IDENTITY_API_VERSION=3
86 export OS_IMAGE_API_VERSION=2
92 if [ -z $DB_EXISTS ]; then
93 openstack user create
--domain default
--password "$NBI_PASSWORD" nbi
94 openstack project create
--domain default
--description "Service Project" service
95 openstack role add
--project service
--user nbi admin
98 while ps
-ef |
grep -v grep |
grep -q apache2
103 # Only reaches this point if apache2 stops running
104 # When this happens exits with error code