[UCA-10] Fix issue with MTU size in dockers
[demo.git] / boot / mso_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 OPENSTACK_API_KEY=$(cat /opt/config/openstack_api_key.txt)
9 GERRIT_BRANCH=$(cat /opt/config/gerrit_branch.txt)
10
11 # Add host name to /etc/host to avoid warnings in openstack images
12 if [[ $CLOUD_ENV != "rackspace" ]]
13 then
14         echo 127.0.0.1 $(hostname) >> /etc/hosts
15 fi
16
17 # Set private IP in /etc/network/interfaces manually in the presence of public interface
18 # Some VM images don't add the private interface automatically, we have to do it during the component installation
19 if [[ $CLOUD_ENV == "openstack_nofloat" ]]
20 then
21         LOCAL_IP=$(cat /opt/config/local_ip_addr.txt)
22         CIDR=$(cat /opt/config/oam_network_cidr.txt)
23         BITMASK=$(echo $CIDR | cut -d"/" -f2)
24
25         # Compute the netmask based on the network cidr
26         if [[ $BITMASK == "8" ]]
27         then
28                 NETMASK=255.0.0.0
29         elif [[ $BITMASK == "16" ]]
30         then
31                 NETMASK=255.255.0.0
32         elif [[ $BITMASK == "24" ]]
33         then
34                 NETMASK=255.255.255.0
35         fi
36
37         echo "auto eth1" >> /etc/network/interfaces
38         echo "iface eth1 inet static" >> /etc/network/interfaces
39         echo "    address $LOCAL_IP" >> /etc/network/interfaces
40         echo "    netmask $NETMASK" >> /etc/network/interfaces
41         ifup eth1
42 fi
43
44 # Download dependencies
45 add-apt-repository -y ppa:openjdk-r/ppa
46 apt-get update
47 apt-get install -y apt-transport-https ca-certificates wget openjdk-8-jdk git ntp ntpdate
48
49 # Download scripts from Nexus
50 curl -k $NEXUS_REPO/org.openecomp.demo/boot/$ARTIFACTS_VERSION/mso_vm_init.sh -o /opt/mso_vm_init.sh
51 curl -k $NEXUS_REPO/org.openecomp.demo/boot/$ARTIFACTS_VERSION/mso_serv.sh -o /opt/mso_serv.sh
52 chmod +x /opt/mso_vm_init.sh
53 chmod +x /opt/mso_serv.sh
54 mv /opt/mso_serv.sh /etc/init.d
55 update-rc.d mso_serv.sh defaults
56
57 # Download and install docker-engine and docker-compose
58 echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
59 apt-get update
60 apt-get install -y linux-image-extra-$(uname -r) linux-image-extra-virtual
61 apt-get install -y --allow-unauthenticated docker-engine
62
63 mkdir /opt/docker
64 curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > /opt/docker/docker-compose
65 chmod +x /opt/docker/docker-compose
66
67 # 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
68 MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
69
70 if [ -s /opt/config/external_dns.txt ]
71 then
72         echo "DOCKER_OPTS=\"--dns $(cat /opt/config/external_dns.txt) --mtu=$MTU\"" >> /etc/default/docker
73 else
74         echo "DOCKER_OPTS=\"--mtu=$MTU\"" >> /etc/default/docker
75 fi
76
77 cp /lib/systemd/system/docker.service /etc/systemd/system
78 sed -i "/ExecStart/s/$/ --mtu=$MTU/g" /etc/systemd/system/docker.service
79 service docker restart
80
81 # DNS IP address configuration
82 echo "nameserver "$DNS_IP_ADDR >> /etc/resolvconf/resolv.conf.d/head
83 resolvconf -u
84
85 # Clone Gerrit repository
86 cd /opt
87 git clone -b $GERRIT_BRANCH --single-branch http://gerrit.onap.org/r/mso/docker-config.git test_lab
88 MSO_ENCRYPTION_KEY=$(cat /opt/test_lab/encryption.key)
89 echo -n "$OPENSTACK_API_KEY" | openssl aes-128-ecb -e -K $MSO_ENCRYPTION_KEY -nosalt | xxd -c 256 -p > /opt/config/api_key.txt
90
91 # Rename network interface in openstack Ubuntu 16.04 images. Then, reboot the VM to pick up changes
92 if [[ $CLOUD_ENV != "rackspace" ]]
93 then
94         sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/g" /etc/default/grub
95         grub-mkconfig -o /boot/grub/grub.cfg
96         sed -i "s/ens[0-9]*/eth0/g" /etc/network/interfaces.d/*.cfg
97         echo 'network: {config: disabled}' >> /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
98         echo "APT::Periodic::Unattended-Upgrade \"0\";" >> /etc/apt/apt.conf.d/10periodic
99         reboot
100 fi
101
102 # Run docker containers. For openstack Ubuntu 16.04 images this will run as a service after the VM has restarted
103 ./mso_vm_init.sh