X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=docker%2FKeystone%2Fscripts%2Fstart.sh;h=8dd61ad6ae0ef4ce50c071cca730f6b16e4cd568;hb=672c66e1181b2d2acc65d3fc5b52505a34eaacd8;hp=1e3709e461fd9045c8a04da120eec65b907cc335;hpb=07e8a24b07bd15fe06d823210bc9ca806811a1d1;p=osm%2Fdevops.git diff --git a/docker/Keystone/scripts/start.sh b/docker/Keystone/scripts/start.sh index 1e3709e4..8dd61ad6 100755 --- a/docker/Keystone/scripts/start.sh +++ b/docker/Keystone/scripts/start.sh @@ -1,6 +1,25 @@ #!/bin/bash +# Copyright 2018 Whitestack, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# For those usages not covered by the Apache License, Version 2.0 please +# contact: esousa@whitestack.com or glavado@whitestack.com +## + DB_EXISTS="" +DB_NOT_EMPTY="" max_attempts=120 function wait_db(){ @@ -46,6 +65,11 @@ if [ -z $DB_EXISTS ]; then mysql -h"$DB_HOST" -P"$DB_PORT" -u"$ROOT_DB_USER" -p"$ROOT_DB_PASSWORD" --default_character_set utf8 -e "CREATE DATABASE keystone" 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'" 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'" +else + 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 + echo "DB keystone is empty" + DB_NOT_EMPTY="y" + fi fi # Setting Keystone database connection @@ -55,7 +79,7 @@ sed -i "721s%.*%connection = mysql+pymysql://keystone:$KEYSTONE_DB_PASSWORD@$DB_ sed -i "2934s%.*%provider = fernet%" /etc/keystone/keystone.conf # Populate Keystone database -if [ -z $DB_EXISTS ]; then +if [ -z $DB_EXISTS ] || [ -z $DB_NOT_EMPTY ]; then su -s /bin/sh -c "keystone-manage db_sync" keystone fi @@ -64,12 +88,15 @@ keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone keystone-manage credential_setup --keystone-user keystone --keystone-group keystone # Bootstrap Keystone service -if [ -z $DB_EXISTS ]; then - keystone-manage bootstrap --bootstrap-password "$ADMIN_PASSWORD" \ - --bootstrap-admin-url http://keystone:5000/v3/ \ - --bootstrap-internal-url http://keystone:5000/v3/ \ - --bootstrap-public-url http://keystone:5000/v3/ \ - --bootstrap-region-id RegionOne +if [ -z $DB_EXISTS ] || [ -z $DB_NOT_EMPTY ]; then + keystone-manage bootstrap \ + --bootstrap-username "$ADMIN_USERNAME" \ + --bootstrap-password "$ADMIN_PASSWORD" \ + --bootstrap-project "$ADMIN_PROJECT" \ + --bootstrap-admin-url "http://$KEYSTONE_HOST:5000/v3/" \ + --bootstrap-internal-url "http://$KEYSTONE_HOST:5000/v3/" \ + --bootstrap-public-url "http://$KEYSTONE_HOST:5000/v3/" \ + --bootstrap-region-id "$REGION_ID" fi # Restart Apache Service @@ -78,10 +105,10 @@ service apache2 restart cat << EOF >> setup_env export OS_PROJECT_DOMAIN_NAME=default export OS_USER_DOMAIN_NAME=default -export OS_PROJECT_NAME=admin -export OS_USERNAME=admin +export OS_PROJECT_NAME=$ADMIN_PROJECT +export OS_USERNAME=$ADMIN_USERNAME export OS_PASSWORD=$ADMIN_PASSWORD -export OS_AUTH_URL=http://keystone:5000/v3 +export OS_AUTH_URL=http://$KEYSTONE_HOST:5000/v3 export OS_IDENTITY_API_VERSION=3 export OS_IMAGE_API_VERSION=2 EOF @@ -89,10 +116,11 @@ EOF source setup_env # Create NBI User -if [ -z $DB_EXISTS ]; then - openstack user create --domain default --password "$NBI_PASSWORD" nbi - openstack project create --domain default --description "Service Project" service - openstack role add --project service --user nbi admin +if [ -z $DB_EXISTS ] || [ -z $DB_NOT_EMPTY ]; then + openstack user create --domain default --password "$SERVICE_PASSWORD" "$SERVICE_USERNAME" + openstack project create --domain default --description "Service Project" "$SERVICE_PROJECT" + openstack role add --project "$SERVICE_PROJECT" --user "$SERVICE_USERNAME" admin + openstack role delete _member_ fi while ps -ef | grep -v grep | grep -q apache2