Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 1 | #!/bin/bash -x |
Gary Wu | a3fb86f | 2018-06-04 16:23:54 -0700 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2018 Huawei Technologies Co., Ltd. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | |
Gary Wu | 3fd6c2a | 2018-10-28 21:44:00 -0700 | [diff] [blame] | 12 | export DEBIAN_FRONTEND=noninteractive |
Gary Wu | 895a4ac | 2018-10-31 12:30:54 -0700 | [diff] [blame] | 13 | HOST_IP=$(hostname -I) |
| 14 | echo $HOST_IP `hostname` >> /etc/hosts |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 15 | printenv |
| 16 | |
| 17 | mkdir -p /opt/config |
Gary Wu | 7a04b3d | 2018-08-15 12:31:46 -0700 | [diff] [blame] | 18 | echo "__docker_version__" > /opt/config/docker_version.txt |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 19 | echo "__rancher_ip_addr__" > /opt/config/rancher_ip_addr.txt |
Gary Wu | ad51372 | 2018-07-26 13:08:47 -0700 | [diff] [blame] | 20 | echo "__rancher_private_ip_addr__" > /opt/config/rancher_private_ip_addr.txt |
Gary Wu | 11c9874 | 2018-05-02 16:19:04 -0700 | [diff] [blame] | 21 | |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 22 | mkdir -p /etc/docker |
Gary Wu | 374498a | 2018-02-06 17:31:04 -0800 | [diff] [blame] | 23 | if [ ! -z "__docker_proxy__" ]; then |
| 24 | cat > /etc/docker/daemon.json <<EOF |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 25 | { |
| 26 | "insecure-registries" : ["__docker_proxy__"] |
| 27 | } |
| 28 | EOF |
Gary Wu | 374498a | 2018-02-06 17:31:04 -0800 | [diff] [blame] | 29 | fi |
| 30 | if [ ! -z "__apt_proxy__" ]; then |
| 31 | cat > /etc/apt/apt.conf.d/30proxy<<EOF |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 32 | Acquire::http { Proxy "http://__apt_proxy__"; }; |
| 33 | Acquire::https::Proxy "DIRECT"; |
| 34 | EOF |
Gary Wu | 374498a | 2018-02-06 17:31:04 -0800 | [diff] [blame] | 35 | fi |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 36 | |
| 37 | mkdir -p /dockerdata-nfs |
Determe, Sebastien (sd378r) | bc0db3d | 2018-10-17 17:10:50 +0200 | [diff] [blame] | 38 | echo "__rancher_private_ip_addr__:/dockerdata-nfs /dockerdata-nfs nfs noauto,noatime,fg,retry=1,x-systemd.automount,_netdev,soft,nolock,intr,tcp,actimeo=1800 0 0" | tee -a /etc/fstab |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 39 | |
Gary Wu | 675eb15 | 2018-10-26 10:50:27 -0700 | [diff] [blame] | 40 | # workaround for OpenStack intermittent failure to change default apt mirrors |
| 41 | sed -i 's|http://archive.ubuntu.com|http://nova.clouds.archive.ubuntu.com|g' /etc/apt/sources.list |
Gary Wu | b0e3650 | 2018-10-16 11:01:07 -0700 | [diff] [blame] | 42 | |
| 43 | while ! hash jq &> /dev/null; do |
| 44 | apt-get -y update |
Gary Wu | 3fd6c2a | 2018-10-28 21:44:00 -0700 | [diff] [blame] | 45 | apt-get -y dist-upgrade |
| 46 | apt-get -y install linux-image-extra-$(uname -r) apt-transport-https ca-certificates curl software-properties-common jq nfs-common |
Gary Wu | b0e3650 | 2018-10-16 11:01:07 -0700 | [diff] [blame] | 47 | sleep 10 |
| 48 | done |
| 49 | |
| 50 | # install docker 17.03 |
| 51 | while ! hash docker &> /dev/null; do |
| 52 | curl -s https://releases.rancher.com/install-docker/__docker_version__.sh | sh |
| 53 | usermod -aG docker ubuntu |
| 54 | sleep 10 |
| 55 | done |
Gary Wu | 3fd6c2a | 2018-10-28 21:44:00 -0700 | [diff] [blame] | 56 | apt-mark hold docker-ce |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 57 | |
| 58 | while [ ! -e /dockerdata-nfs/rancher_agent_cmd.sh ]; do |
| 59 | mount /dockerdata-nfs |
Gary Wu | b0e3650 | 2018-10-16 11:01:07 -0700 | [diff] [blame] | 60 | sleep 10 |
Gary Wu | c98156d | 2018-01-18 12:03:26 -0800 | [diff] [blame] | 61 | done |
Gary Wu | b0e3650 | 2018-10-16 11:01:07 -0700 | [diff] [blame] | 62 | |
| 63 | cd ~ |
Gary Wu | 11c9874 | 2018-05-02 16:19:04 -0700 | [diff] [blame] | 64 | cp /dockerdata-nfs/rancher_agent_cmd.sh . |
Gary Wu | 3fd6c2a | 2018-10-28 21:44:00 -0700 | [diff] [blame] | 65 | sed -i "s/docker run/docker run -e CATTLE_HOST_LABELS='__host_label__=true' -e CATTLE_AGENT_IP=${HOST_IP}/g" rancher_agent_cmd.sh |
Gary Wu | 11c9874 | 2018-05-02 16:19:04 -0700 | [diff] [blame] | 66 | source rancher_agent_cmd.sh |
Gary Wu | 3fd6c2a | 2018-10-28 21:44:00 -0700 | [diff] [blame] | 67 | sleep 1m |
| 68 | |
| 69 | reboot |