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 | # Copyright 2018 Huawei Technologies Co., Ltd. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
Gary Wu | 3fd6c2a | 2018-10-28 21:44:00 -0700 | [diff] [blame] | 10 | export DEBIAN_FRONTEND=noninteractive |
Gary Wu | b718998 | 2018-11-14 10:01:37 -0800 | [diff] [blame] | 11 | echo "__host_private_ip_addr__ $(hostname)" >> /etc/hosts |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 12 | printenv |
| 13 | |
| 14 | mkdir -p /opt/config |
Gary Wu | 7a04b3d | 2018-08-15 12:31:46 -0700 | [diff] [blame] | 15 | echo "__docker_version__" > /opt/config/docker_version.txt |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 16 | echo "__rancher_ip_addr__" > /opt/config/rancher_ip_addr.txt |
Gary Wu | ad51372 | 2018-07-26 13:08:47 -0700 | [diff] [blame] | 17 | echo "__rancher_private_ip_addr__" > /opt/config/rancher_private_ip_addr.txt |
Gary Wu | b718998 | 2018-11-14 10:01:37 -0800 | [diff] [blame] | 18 | echo "__host_private_ip_addr__" > /opt/config/host_private_ip_addr.txt |
Gary Wu | b8be70a | 2018-11-17 17:14:38 -0800 | [diff] [blame] | 19 | echo "__mtu__" > /opt/config/mtu.txt |
Gary Wu | 11c9874 | 2018-05-02 16:19:04 -0700 | [diff] [blame] | 20 | |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 21 | mkdir -p /etc/docker |
Gary Wu | 374498a | 2018-02-06 17:31:04 -0800 | [diff] [blame] | 22 | if [ ! -z "__docker_proxy__" ]; then |
| 23 | cat > /etc/docker/daemon.json <<EOF |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 24 | { |
Gary Wu | b8be70a | 2018-11-17 17:14:38 -0800 | [diff] [blame] | 25 | "mtu": __mtu__, |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 26 | "insecure-registries" : ["__docker_proxy__"] |
| 27 | } |
| 28 | EOF |
Gary Wu | b8be70a | 2018-11-17 17:14:38 -0800 | [diff] [blame] | 29 | else |
| 30 | cat > /etc/docker/daemon.json <<EOF |
| 31 | { |
| 32 | "mtu": __mtu__ |
| 33 | } |
| 34 | EOF |
Gary Wu | 374498a | 2018-02-06 17:31:04 -0800 | [diff] [blame] | 35 | fi |
| 36 | if [ ! -z "__apt_proxy__" ]; then |
Gary Wu | b718998 | 2018-11-14 10:01:37 -0800 | [diff] [blame] | 37 | cat > /etc/apt/apt.conf.d/30proxy <<EOF |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 38 | Acquire::http { Proxy "http://__apt_proxy__"; }; |
| 39 | Acquire::https::Proxy "DIRECT"; |
| 40 | EOF |
Gary Wu | 374498a | 2018-02-06 17:31:04 -0800 | [diff] [blame] | 41 | fi |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 42 | |
Gary Wu | 48a3294 | 2018-11-08 07:34:49 -0800 | [diff] [blame] | 43 | # tune ext4 for performance |
| 44 | sed -i 's/defaults/defaults,noatime,commit=60,barrier=0/' /etc/fstab |
| 45 | |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 46 | mkdir -p /dockerdata-nfs |
Determe, Sebastien (sd378r) | bc0db3d | 2018-10-17 17:10:50 +0200 | [diff] [blame] | 47 | 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] | 48 | |
Gary Wu | 675eb15 | 2018-10-26 10:50:27 -0700 | [diff] [blame] | 49 | # workaround for OpenStack intermittent failure to change default apt mirrors |
| 50 | 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] | 51 | |
| 52 | while ! hash jq &> /dev/null; do |
| 53 | apt-get -y update |
Gary Wu | 3fd6c2a | 2018-10-28 21:44:00 -0700 | [diff] [blame] | 54 | apt-get -y dist-upgrade |
| 55 | 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] | 56 | sleep 10 |
| 57 | done |
| 58 | |
| 59 | # install docker 17.03 |
| 60 | while ! hash docker &> /dev/null; do |
| 61 | curl -s https://releases.rancher.com/install-docker/__docker_version__.sh | sh |
| 62 | usermod -aG docker ubuntu |
| 63 | sleep 10 |
| 64 | done |
Gary Wu | 3fd6c2a | 2018-10-28 21:44:00 -0700 | [diff] [blame] | 65 | apt-mark hold docker-ce |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 66 | |
Gary Wu | b718998 | 2018-11-14 10:01:37 -0800 | [diff] [blame] | 67 | # Enable autorestart when VM reboots |
| 68 | update-rc.d k8s_vm_init_serv defaults |