152e67f897105558760bac1068b7237626e26e60
[demo.git] / boot / mr_install.sh
1 #!/bin/bash
2
3 # Read configuration files
4 ARTIFACTS_VERSION=$(cat /opt/config/artifacts_version.txt)
5 DNS_IP_ADDR=$(cat /opt/config/dns_ip_addr.txt)
6 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
7 GERRIT_BRANCH=$(cat /opt/config/gerrit_branch.txt)
8 MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
9 CODE_REPO=$(cat /opt/config/remote_repo.txt)
10 HTTP_PROXY=$(cat /opt/config/http_proxy.txt)
11 HTTPS_PROXY=$(cat /opt/config/https_proxy.txt)
12
13 if [ $HTTP_PROXY != "no_proxy" ]
14 then
15     export http_proxy=$HTTP_PROXY
16     export https_proxy=$HTTPS_PROXY
17 fi
18
19 # Add host name to /etc/host to avoid warnings in openstack images
20 if [[ $CLOUD_ENV != "rackspace" ]]
21 then
22         echo 127.0.0.1 $(hostname) >> /etc/hosts
23
24         # Allow remote login as root
25         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
26         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
27 fi
28
29 # Set private IP in /etc/network/interfaces manually in the presence of public interface
30 # Some VM images don't add the private interface automatically, we have to do it during the component installation
31 if [[ $CLOUD_ENV == "openstack_nofloat" ]]
32 then
33         LOCAL_IP=$(cat /opt/config/local_ip_addr.txt)
34         CIDR=$(cat /opt/config/oam_network_cidr.txt)
35         BITMASK=$(echo $CIDR | cut -d"/" -f2)
36
37         # Compute the netmask based on the network cidr
38         if [[ $BITMASK == "8" ]]
39         then
40                 NETMASK=255.0.0.0
41         elif [[ $BITMASK == "16" ]]
42         then
43                 NETMASK=255.255.0.0
44         elif [[ $BITMASK == "24" ]]
45         then
46                 NETMASK=255.255.255.0
47         fi
48
49         echo "auto eth1" >> /etc/network/interfaces
50         echo "iface eth1 inet static" >> /etc/network/interfaces
51         echo "    address $LOCAL_IP" >> /etc/network/interfaces
52         echo "    netmask $NETMASK" >> /etc/network/interfaces
53         echo "    mtu $MTU" >> /etc/network/interfaces
54         ifup eth1
55 fi
56
57 # Download dependencies
58 apt-get update
59 apt-get install -y apt-transport-https ca-certificates wget make git ntp ntpdate
60
61 # Download scripts from Nexus
62 # a) scripts for message router (mr)
63 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip mr_vm_init.sh > /opt/mr_vm_init.sh
64 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip mr_serv.sh > /opt/mr_serv.sh
65 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip imagetest.sh > /opt/imagetest.sh
66 chmod +x /opt/imagetest.sh
67 chmod +x /opt/mr_vm_init.sh
68 chmod +x /opt/mr_serv.sh
69 mv /opt/mr_serv.sh /etc/init.d
70 update-rc.d mr_serv.sh defaults
71
72 # b) scripts for bus controller (dbcl)
73 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip dbcl_vm_init.sh > /opt/dbcl_vm_init.sh
74 chmod +x /opt/dbcl_vm_init.sh
75
76 # Download and install docker-engine and docker-compose
77 echo "deb https://apt.dockerproject.org/repo ubuntu-$(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/docker.list
78 apt-get update
79 apt-get install -y linux-image-extra-$(uname -r) linux-image-extra-virtual
80 apt-get install -y --allow-unauthenticated docker-engine
81
82 mkdir /opt/docker
83 curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > /opt/docker/docker-compose
84 chmod +x /opt/docker/docker-compose
85
86 # 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
87 DNS_FLAG=""
88 if [ -s /opt/config/dns_ip_addr.txt ]
89 then
90         DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/dns_ip_addr.txt) "
91 fi
92 if [ -s /opt/config/external_dns.txt ]
93 then
94         DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/external_dns.txt) "
95 fi
96 echo "DOCKER_OPTS=\"$DNS_FLAG--mtu=$MTU\"" >> /etc/default/docker
97
98 cp /lib/systemd/system/docker.service /etc/systemd/system
99 sed -i "/ExecStart/s/$/ --mtu=$MTU/g" /etc/systemd/system/docker.service
100 if [ $HTTP_PROXY != "no_proxy" ]
101 then
102 cd /opt
103 ./imagetest.sh
104 fi
105 service docker restart
106
107 # DNS IP address configuration
108 echo "nameserver "$DNS_IP_ADDR >> /etc/resolvconf/resolv.conf.d/head
109 resolvconf -u
110
111 # Clone Gerrit repository and run docker containers
112 cd /opt
113 git clone -b $GERRIT_BRANCH --single-branch $CODE_REPO /opt/startup-vm-message-router
114 ./mr_vm_init.sh