5f34aae8c5159ec9c0f3364884a9a74eef8e6cb0
[portal.git] / deliveries / portal_vm_init.sh
1 #!/bin/bash
2 # Starts docker containers for ONAP Portal
3
4 # be verbose
5 set -x
6
7 # Refresh source area with start scripts
8 cd /opt/portal
9 git pull
10 cd /opt
11
12 # Establish environment variables
13 NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt)
14 NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt)
15 NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt)
16 DOCKER_IMAGE_VERSION=$(cat /opt/config/docker_version.txt)
17
18 # Get container, image and tag names used below
19 source portal/deliveries/os_settings.sh
20
21 # Unpack property files
22 unzip -o portal/deliveries/etc.zip -d /PROJECT/OpenSource/UbuntuEP/
23
24 # Refresh images
25 docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
26 docker pull $NEXUS_DOCKER_REPO/openecomp/${DB_TAG_NAME}:$DOCKER_IMAGE_VERSION
27 docker pull $NEXUS_DOCKER_REPO/openecomp/${EP_TAG_NAME}:$DOCKER_IMAGE_VERSION
28 docker pull $NEXUS_DOCKER_REPO/openecomp/${WMS_TAG_NAME}:$DOCKER_IMAGE_VERSION
29
30 # Remove lingering containers; order matters.
31 docker rm -f $DB_CONT_NAME
32 docker rm -f $DB_VOL_NAME
33 docker rm -f $EP_CONT_NAME
34 docker rm -f $WMS_CONT_NAME
35
36 docker create --name $DB_VOL_NAME -v /var/lib/mysql mariadb
37 docker tag $NEXUS_DOCKER_REPO/openecomp/${DB_TAG_NAME}:$DOCKER_IMAGE_VERSION $DB_IMG_NAME
38 docker tag $NEXUS_DOCKER_REPO/openecomp/${EP_TAG_NAME}:$DOCKER_IMAGE_VERSION $EP_IMG_NAME
39 # WMS image has no version in the registry
40 docker tag $NEXUS_DOCKER_REPO/openecomp/${WMS_TAG_NAME}:$DOCKER_IMAGE_VERSION ${WMS_IMG_NAME}:latest
41
42 # Recreate the named containers
43 cd portal/deliveries
44 echo "Starting database"
45 ./dbstart.sh
46 echo "Delaying for database"
47 sleep 10
48 echo "Starting apps"
49 ./new_start.sh
50 echo "Starting widget-ms"
51 ./widget_ms_start.sh
52
53 sleep 180
54
55 if [ ! -e /opt/config/boot.txt ]
56 then
57         if [ -e /opt/config/public_ip.txt ]
58         then
59                 IP_ADDRESS=$(cat /opt/config/public_ip.txt)
60         else
61                 IP_ADDRESS=$(ifconfig eth0 | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2)
62         fi
63         # Wait until MySQL is running...
64         while [[ $(netstat -vulntp |grep -i mysql | awk '{print $4}') != ":::3306" ]]
65         do
66                 sleep 1
67         done
68         # no longer necessary; done at docker build time
69         # mysql -u root -p'Aa123456' -h $IP_ADDRESS < /opt/portal/deliveries/Apps_Users_OnBoarding_Script.sql
70         echo "yes" > /opt/config/boot.txt
71 fi