Merge "Exposing PM and ELK stack ports"
[osm/devops.git] / docker / Keystone / scripts / start.sh
index 1530387..1e3709e 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+DB_EXISTS=""
+
 max_attempts=120
 function wait_db(){
     db_host=$1
@@ -27,8 +29,7 @@ function is_db_created() {
     db_pswd=$4
     db_name=$5
 
-    RESULT=`mysqlshow -h"$db_host" -P"$db_port" -u"$db_user" -p"$db_pswd" | grep -v Wildcard | grep -o $db_name`
-    if [ "$RESULT" == "$db_name" ]; then
+    if mysqlshow -h"$db_host" -P"$db_port" -u"$db_user" -p"$db_pswd" | grep -v Wildcard | grep -q $db_name; then
         echo "DB $db_name exists"
         return 0
     else
@@ -37,8 +38,6 @@ function is_db_created() {
     fi
 }
 
-KEYSTONE_IP=`ifconfig eth0 | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*'`
-
 wait_db "$DB_HOST" "$DB_PORT" || exit 1
 
 is_db_created "$DB_HOST" "$DB_PORT" "$ROOT_DB_USER" "$ROOT_DB_PASSWORD" "keystone" && DB_EXISTS="Y"
@@ -67,25 +66,40 @@ keystone-manage credential_setup --keystone-user keystone --keystone-group keyst
 # Bootstrap Keystone service
 if [ -z $DB_EXISTS ]; then
     keystone-manage bootstrap --bootstrap-password "$ADMIN_PASSWORD" \
-        --bootstrap-admin-url http://"$KEYSTONE_IP":5000/v3/ \
-        --bootstrap-internal-url http://"$KEYSTONE_IP":5000/v3/ \
-        --bootstrap-public-url http://"$KEYSTONE_IP":5000/v3/ \
+        --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
 fi
 
 # Restart Apache Service
 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_PASSWORD=$ADMIN_PASSWORD
+export OS_AUTH_URL=http://keystone:5000/v3
+export OS_IDENTITY_API_VERSION=3
+export OS_IMAGE_API_VERSION=2
+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 defaul --description "Service Project" service
+    openstack project create --domain default --description "Service Project" service
     openstack role add --project service --user nbi admin
 fi
 
-while [ $(ps -ef | grep -v grep | grep apache2 | wc -l) -ne 0 ]
+while ps -ef | grep -v grep | grep -q apache2
 do
     sleep 60
 done
 
+# Only reaches this point if apache2 stops running
+# When this happens exits with error code
 exit 1