bee4bef66fd4f34a9b791eab086955803b2c6aa1
[logging-analytics.git] / deploy / aws / oom_cluster_host_install.sh
1 #!/bin/bash
2 #############################################################################
3 #
4 # Copyright © 2018 Amdocs.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #        http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 #############################################################################
18 # v20180815
19 # Amazon AWS specific EFS/NFS share and rancher host join script for each cluster node
20 # https://wiki.onap.org/display/DW/Cloud+Native+Deployment
21 # source from https://jira.onap.org/browse/OOM-320
22 # Michael O'Brien
23
24 usage() {
25 cat <<EOF
26 Usage: $0 [PARAMs]
27 example
28  master
29  sudo ./cluster.sh -n false -s cl.onap.info -e fs-00c0f00 -r us-east-2
30  clients
31  sudo ./cluster.sh -n true -s cl.onap.info -e fs-00c0f00 -r us-east-2 -t 23D4:15:qQ -c false -a host1.onap.info -v true
32  sudo ./oom_cluster_host_install.sh -n true -s cd.onap.cloud -e 1 -r us-east-2 -t token -c false -a 104.209.158.156 -v true
33 Prereq:
34   You must create an EFS (NFS wrapper) on AWS
35
36 -u                      : Display usage
37 -n [true|false]         : is node (non master)
38 -s [master server]      : target server (ip or FQDN only)
39 -e [AWS efs id]         : AWS Elastic File System ID prefix
40 -r [AWS region prefix]  : AWS Region prefix
41 -t [token]              : registration token
42 -h [agent ver]          : agent version (default 1.2.10 for 1.6.18
43 -c [true/false]         : use computed client address
44 -a [IP address]         : client address ip - no FQDN
45 -v [validate true/false]: optional
46 EOF
47 }
48
49 register_node() {
50     #constants
51     DOCKERDATA_NFS=dockerdata-nfs
52     DOCKER_VER=17.03
53     USERNAME=ubuntu
54     PORT=8880
55
56     if [[ "$IS_NODE" != false ]]; then
57         sudo curl https://releases.rancher.com/install-docker/$DOCKER_VER.sh | sh
58         sudo usermod -aG docker $USERNAME
59     fi
60     sudo apt-get install nfs-common -y
61     sudo mkdir /$DOCKERDATA_NFS
62     sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 $AWS_EFS.efs.$AWS_REGION.amazonaws.com:/ /$DOCKERDATA_NFS
63     if [[ "$IS_NODE" != false ]]; then
64         echo "Running agent docker..."
65         if [[ "$COMPUTEADDRESS" != false ]]; then
66             echo "sudo docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v$AGENT_VER http://$MASTER:$PORT/v1/scripts/$TOKEN"
67             sudo docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v$AGENT_VER http://$MASTER:$PORT/v1/scripts/$TOKEN
68         else
69             echo "sudo docker run -e CATTLE_AGENT_IP=\"$ADDRESS\" --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v$AGENT_VER http://$MASTER:$PORT/v1/scripts/$TOKEN"
70             sudo docker run -e CATTLE_AGENT_IP="$ADDRESS" --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v$AGENT_VER http://$MASTER:$PORT/v1/scripts/$TOKEN
71         fi
72     fi
73 }
74
75 IS_NODE=false
76 MASTER=
77 TOKEN=
78 AWS_REGION=
79 AWS_EFS=
80 AGENT_VER=1.2.10
81 COMPUTEADDRESS=true
82 ADDRESS=
83 VALIDATE=
84 while getopts ":u:n:s:e:r:t:h:c:a:v" PARAM; do
85   case $PARAM in
86     u)
87       usage
88       exit 1
89       ;;
90     n)
91       IS_NODE=${OPTARG}
92       ;;
93     s)
94       MASTER=${OPTARG}
95       ;;
96     e)
97       AWS_EFS=${OPTARG}
98       ;;
99     r)
100       AWS_REGION=${OPTARG}
101       ;;
102     t)
103       TOKEN=${OPTARG}
104       ;;
105     h)
106       AGENT_VER=${OPTARG}
107       ;;
108     c)
109       COMPUTEADDRESS=${OPTARG}
110       ;;
111     a)
112       ADDRESS=${OPTARG}
113       ;;
114     v)
115       VALIDATE=${OPTARG}
116       ;;
117     ?)
118       usage
119       exit
120       ;;
121   esac
122 done
123
124 if [ -z $MASTER ]; then
125   usage
126   exit 1
127 fi
128
129 register_node  $IS_NODE $MASTER $AWS_EFS $AWS_REGION $TOKEN $AGENT_VER $COMPUTEADDRESS $ADDRESS $VALIDATE
130 echo "check dockerdata-nfs"
131 sudo ls /dockerdata-nfs
132 echo "if you get http://$MASTER:8880/v1 is not accessible (The requested URL returned error: 404 Not Found) - check your token"
133 printf "**** Success: Done ****\n"