blob: 62340c11c6786935898e66d4dc5c16bf27702496 [file] [log] [blame]
Gary Wu1ff56672018-01-17 20:51:45 -08001#!/bin/bash -x
Gary Wua3fb86f2018-06-04 16:23:54 -07002#
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 Wu3fd6c2a2018-10-28 21:44:00 -070012export DEBIAN_FRONTEND=noninteractive
Gary Wu895a4ac2018-10-31 12:30:54 -070013HOST_IP=$(hostname -I)
14echo $HOST_IP `hostname` >> /etc/hosts
Gary Wu1ff56672018-01-17 20:51:45 -080015printenv
16
17mkdir -p /opt/config
Gary Wu7a04b3d2018-08-15 12:31:46 -070018echo "__docker_version__" > /opt/config/docker_version.txt
Gary Wu1ff56672018-01-17 20:51:45 -080019echo "__rancher_ip_addr__" > /opt/config/rancher_ip_addr.txt
Gary Wuad513722018-07-26 13:08:47 -070020echo "__rancher_private_ip_addr__" > /opt/config/rancher_private_ip_addr.txt
Gary Wu11c98742018-05-02 16:19:04 -070021
Gary Wu1ff56672018-01-17 20:51:45 -080022mkdir -p /etc/docker
Gary Wu374498a2018-02-06 17:31:04 -080023if [ ! -z "__docker_proxy__" ]; then
24 cat > /etc/docker/daemon.json <<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080025{
26 "insecure-registries" : ["__docker_proxy__"]
27}
28EOF
Gary Wu374498a2018-02-06 17:31:04 -080029fi
30if [ ! -z "__apt_proxy__" ]; then
31 cat > /etc/apt/apt.conf.d/30proxy<<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080032Acquire::http { Proxy "http://__apt_proxy__"; };
33Acquire::https::Proxy "DIRECT";
34EOF
Gary Wu374498a2018-02-06 17:31:04 -080035fi
Gary Wu14a6b302018-05-01 15:59:28 -070036
Gary Wu48a32942018-11-08 07:34:49 -080037# tune ext4 for performance
38sed -i 's/defaults/defaults,noatime,commit=60,barrier=0/' /etc/fstab
39
Gary Wu14a6b302018-05-01 15:59:28 -070040mkdir -p /dockerdata-nfs
Determe, Sebastien (sd378r)bc0db3d2018-10-17 17:10:50 +020041echo "__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 Wu14a6b302018-05-01 15:59:28 -070042
Gary Wu675eb152018-10-26 10:50:27 -070043# workaround for OpenStack intermittent failure to change default apt mirrors
44sed -i 's|http://archive.ubuntu.com|http://nova.clouds.archive.ubuntu.com|g' /etc/apt/sources.list
Gary Wub0e36502018-10-16 11:01:07 -070045
46while ! hash jq &> /dev/null; do
47 apt-get -y update
Gary Wu3fd6c2a2018-10-28 21:44:00 -070048 apt-get -y dist-upgrade
49 apt-get -y install linux-image-extra-$(uname -r) apt-transport-https ca-certificates curl software-properties-common jq nfs-common
Gary Wub0e36502018-10-16 11:01:07 -070050 sleep 10
51done
52
53# install docker 17.03
54while ! hash docker &> /dev/null; do
55 curl -s https://releases.rancher.com/install-docker/__docker_version__.sh | sh
56 usermod -aG docker ubuntu
57 sleep 10
58done
Gary Wu3fd6c2a2018-10-28 21:44:00 -070059apt-mark hold docker-ce
Gary Wu14a6b302018-05-01 15:59:28 -070060
61while [ ! -e /dockerdata-nfs/rancher_agent_cmd.sh ]; do
62 mount /dockerdata-nfs
Gary Wub0e36502018-10-16 11:01:07 -070063 sleep 10
Gary Wuc98156d2018-01-18 12:03:26 -080064done
Gary Wub0e36502018-10-16 11:01:07 -070065
66cd ~
Gary Wu11c98742018-05-02 16:19:04 -070067cp /dockerdata-nfs/rancher_agent_cmd.sh .
Gary Wu3fd6c2a2018-10-28 21:44:00 -070068sed -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 Wu11c98742018-05-02 16:19:04 -070069source rancher_agent_cmd.sh
Gary Wu3fd6c2a2018-10-28 21:44:00 -070070sleep 1m
71
72reboot