[UCA-10] Fix issue with MTU size in dockers
[demo.git] / boot / mr_install.sh
1 #!/bin/bash
2
3 # Read configuration files
4 NEXUS_REPO=$(cat /opt/config/nexus_repo.txt)
5 ARTIFACTS_VERSION=$(cat /opt/config/artifacts_version.txt)
6 DNS_IP_ADDR=$(cat /opt/config/dns_ip_addr.txt)
7 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
8 GERRIT_BRANCH=$(cat /opt/config/gerrit_branch.txt)
9
10 # Add host name to /etc/host to avoid warnings in openstack images
11 if [[ $CLOUD_ENV != "rackspace" ]]
12 then
13         echo 127.0.0.1 $(hostname) >> /etc/hosts
14 fi
15
16 # Set private IP in /etc/network/interfaces manually in the presence of public interface
17 # Some VM images don't add the private interface automatically, we have to do it during the component installation
18 if [[ $CLOUD_ENV == "openstack_nofloat" ]]
19 then
20         LOCAL_IP=$(cat /opt/config/local_ip_addr.txt)
21         CIDR=$(cat /opt/config/oam_network_cidr.txt)
22         BITMASK=$(echo $CIDR | cut -d"/" -f2)
23
24         # Compute the netmask based on the network cidr
25         if [[ $BITMASK == "8" ]]
26         then
27                 NETMASK=255.0.0.0
28         elif [[ $BITMASK == "16" ]]
29         then
30                 NETMASK=255.255.0.0
31         elif [[ $BITMASK == "24" ]]
32         then
33                 NETMASK=255.255.255.0
34         fi
35
36         echo "auto eth1" >> /etc/network/interfaces
37         echo "iface eth1 inet static" >> /etc/network/interfaces
38         echo "    address $LOCAL_IP" >> /etc/network/interfaces
39         echo "    netmask $NETMASK" >> /etc/network/interfaces
40         ifup eth1
41 fi
42
43 # Download dependencies
44 add-apt-repository -y ppa:openjdk-r/ppa
45 apt-get update
46 apt-get install -y apt-transport-https ca-certificates wget make openjdk-8-jdk git ntp ntpdate
47
48 # Download scripts from Nexus
49 curl -k $NEXUS_REPO/org.openecomp.demo/boot/$ARTIFACTS_VERSION/mr_vm_init.sh -o /opt/mr_vm_init.sh
50 curl -k $NEXUS_REPO/org.openecomp.demo/boot/$ARTIFACTS_VERSION/mr_serv.sh -o /opt/mr_serv.sh
51 chmod +x /opt/mr_vm_init.sh
52 chmod +x /opt/mr_serv.sh
53 mv /opt/mr_serv.sh /etc/init.d
54 update-rc.d mr_serv.sh defaults
55
56 # Download and install docker-engine and docker-compose
57 echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list
58 apt-get update
59 apt-get install -y linux-image-extra-$(uname -r) linux-image-extra-virtual
60 apt-get install -y --allow-unauthenticated docker-engine
61
62 mkdir /opt/docker
63 curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > /opt/docker/docker-compose
64 chmod +x /opt/docker/docker-compose
65
66 # Set the MTU size of docker containers to the minimum MTU size supported by vNICs. OpenStack deployments may need to know the external DNS IP
67 MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
68
69 if [ -s /opt/config/external_dns.txt ]
70 then
71         echo "DOCKER_OPTS=\"--dns $(cat /opt/config/external_dns.txt) --mtu=$MTU\"" >> /etc/default/docker
72 else
73         echo "DOCKER_OPTS=\"--mtu=$MTU\"" >> /etc/default/docker
74 fi
75
76 cp /lib/systemd/system/docker.service /etc/systemd/system
77 sed -i "/ExecStart/s/$/ --mtu=$MTU/g" /etc/systemd/system/docker.service
78 service docker restart
79
80 # DNS IP address configuration
81 echo "nameserver "$DNS_IP_ADDR >> /etc/resolvconf/resolv.conf.d/head
82 resolvconf -u
83
84 # Clone Gerrit repository and run docker containers
85 cd /opt
86 git clone -b $GERRIT_BRANCH --single-branch http://gerrit.onap.org/r/dcae/demo/startup/message-router.git dcae-startup-vm-message-router
87 ./mr_vm_init.sh