-
Notifications
You must be signed in to change notification settings - Fork 0
/
datafabric_container_setup.sh
415 lines (367 loc) · 17.2 KB
/
datafabric_container_setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
#!/bin/bash
#set -x
IMAGE="maprtech/edf-seed-container:latest"
INTERFACE="en0"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
usage()
{
echo "This script will take of deploying edf on seed node."
echo
echo "Syntax: ./datafabric_container_setup.sh [-i|--image] [-p|--publicipv4dns] [-f|--proxyfiledetails]"
echo "options:"
echo "-i|--image this is optional,By defaul it will pull image having latest tag,
we can also provide image which has custom tag example:maprtech/edf-seed-container:7.4.0_9.1.2"
echo "-p|--publicipv4dns is the public IPv4 DNS and needed for cloud deployed seed nodes. Note that both inbound and outbound trafic on port 8443
needs to be enabled on the cloud instance. Otherwise, the Data Fabric UI cannot be acessible"
echo "-f|--proxyfiledetails is the location of file from where proxy details provided by user are copied to docker container."
echo
}
os_name=$(. /etc/os-release 2> /dev/null && echo "$ID") &> /dev/null
install_docker_linux()
{
echo "Docker is not present on the system.Installing it.."
echo "Docker installation may take 6 to 8 minutes..."
echo "There is no input/intervention required from user side"
if [ $os_name == "ubuntu" ]; then
sudo apt-get update > /dev/null
sudo apt-get -y install ca-certificates curl gnupg > /dev/null
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - > /dev/null 2>&1
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg trusted=yes] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update > /dev/null 2>&1
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin > /dev/null 2>&1
systemctl daemon-reload > /dev/null 2>&1
systemctl restart docker > /dev/null 2>&1
systemctl enable docker > /dev/null 2>&1
elif [ $os_name == "rhel" ]; then
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo > /dev/null
dnf install docker-ce --nobest -y > /dev/null
elif [ $os_name == "centos" ]; then
sudo yum install -y yum-utils > /dev/null
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo > /dev/null
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
fi
sleep 120
systemctl start docker > /dev/null 2>&1
#check if docker is installed and running
docker info > /dev/null 2>&1
if [ $? != 0 ] ; then
echo
echo "Docker installation on the node where this script is ran is not successfull.Please install docker manually to proceed forward"
exit
else
echo
echo "Docker installation on node from script was successfull"
fi
}
#checking if required memory is present or not
os_vers=`uname -s` > /dev/null 2>&1
memory_requirement=1
if [ "$os_vers" == "Darwin" ]; then
memory_avilable_mac=$(system_profiler SPHardwareDataType | grep "Memory" | awk '{print $2}') &>/dev/null
if [ $memory_avilable_mac -lt 32 ] ; then
echo -e "${GREEN}RAM NEEDED \t :\t 32 GB"
echo -e "${RED}RAM AVILABLE \t :\t $memory_avilable_mac GB"
echo -e "${RED}Please try to spin up seed node on client having sufficient memory${NC}"
memory_requirement=0
exit
fi
fi
if [ "$os_vers" == "Linux" ]; then
memory_avilable_linux=$(cat /proc/meminfo | grep MemTotal | awk '{print $2}') &>/dev/null
if [ $memory_avilable_linux -lt 25165824 ]; then
echo -e "${GREEN}RAM NEEDED \t :\t 25165824"
echo -e "${RED}RAM AVILABLE \t :\t $memory_avilable_linux"
echo -e "${RED}Please try to spin up seed node on client having sufficient memory${NC}"
memory_requirement=0
exit
fi
fi
#setting default value of container_engine to docker. Here container_engine refers to the container runtime installed.
container_engine='docker'
# Check if Docker is installed
docker info > /dev/null 2>&1
DOCKER_STATUS=$?
# Check if Podman is installed
podman info > /dev/null 2>&1
PODMAN_STATUS=$?
# If Podman is installed, set container_engine=podman
if [ $PODMAN_STATUS = 0 ]; then
container_engine='podman'
IMAGE="docker.io/maprtech/edf-seed-container:latest"
fi
# If docker is installed, set container_engine=docker
if [ $DOCKER_STATUS = 0 ]; then
container_engine='docker'
fi
# If neither Docker nor Podman is available, install docker.
if [ $DOCKER_STATUS != 0 ] && [ $PODMAN_STATUS != 0 ]; then
if [ "$os_vers" == "Darwin" ];then
echo -e "${RED}Docker is not installed/not-running on the MacBook where this script is ran.Please install/start docker to proceed forward"
echo -e "${GREEN}Reference link to install : https://docs.docker.com/desktop/install/mac-install/${NC}"
exit
elif [ "$os_vers" == "Linux" ]; then
install_docker_linux
fi
fi
#check connectivity to docker hub
container_engine_running=1
$container_engine run hello-world > /dev/null 2>&1
if [ $? != 0 ]; then
echo -e "${RED}$container_engine is not running on the system"
echo -e "${RED}$container_engine is installed/running on the system but we are not able to pull images from docker"
echo -e "${RED}Please check internet connectivity or if the machine is behind a proxy and take appropriate action accordingly${NC}"
container_engine_running=0
exit
fi
#remove the hello-world image we ran in earlier step
CID_Hello=$($container_engine ps -a | grep hello-world | awk '{ print $1 }' | tail -1 )
if [ -n "$CID_Hello" ]; then
$container_engine stop $CID_Hello > /dev/null 2>&1
$container_engine rm -f $CID_Hello > /dev/null 2>&1
fi
lsof_installed=1
if [ "$os_vers" == "Linux" ]; then
if [ $os_name == "ubuntu" ] ; then
if [ $(dpkg -l | grep -i lsof | wc -l) == 0 ]; then
lsof_installed=0
fi
elif [ $os_name == "centos" ] || [ $os_name == "rhel" ]; then
if [ $(rpm -qa | grep -i lsof | wc -l) == 0 ]; then
lsof_installed=0
fi
fi
fi
if [ $lsof_installed == 1 ];then
#check if ports used by datafabric is already used by some other process
$container_engine ps -a | grep edf-seed-container > /dev/null 2>&1
if [ $? != 0 ]; then
seednodeports='7221 5660 5692 5724 5756 8443 8188 8080 7222 5181'
pc=0
for port in $seednodeports
do
result=`lsof -i:${port} | grep LISTEN`
retval=$?
if [ $retval -eq 0 ]; then
echo "${port} port is being used"
pc=1
fi
done
if [ $pc -eq 1 ]; then
echo -e "${RED}it seems to be that some existing application using the required ports so please make sure to clean them up before attempting again${NC}"
exit 1
fi
fi
else
echo -e "${YELLOW}lsof command is not installed on the system"
echo -e "${YELLOW}We will not be able to check if ports 7221 5660 5692 5724 5756 8443 8188 8080 7222 5181 needed by Bootstrap node are being used by any other process/application"
echo -e "${YELLOW}If above mentioned ports are in use then the container will fail to start${NC}"
fi
if [ $memory_requirement == 1 ] && [ $container_engine_running == 1 ] && [ $lsof_installed == 1 ]; then
echo -e "\t\t${GREEN}RAM NEEDED \t :\t AVAILABLE"
echo -e "\t\t${GREEN}$container_engine STATUS \t :\t RUNNING"
echo -e "\t\t${GREEN}PORTS NEEDED \t :\t AVAILABLE"
echo -e "\t\tPROCEEDING FORWARD WITH DEPLOYING SEED NODE${NC}"
fi
while [ $# -gt 0 ]
do
case "$1" in
-i|--image) shift;
IMAGE=$1;;
-p|--publicipv4dns) shift;
PUBLICIPV4DNS=$1;;
-f|--proxyfiledetails) shift;
PROXYFILEDETAILS=$1;;
*) shift;
usage
exit;;
esac
shift
done
which ipconfig &>/dev/null
if [ $? -eq 0 ]; then
INTERFACE=$(route -n get default | grep interface | awk '{print $2}')
IP=$(ipconfig getifaddr $INTERFACE)
else
INTERFACE=$(ip route | grep default | awk '{print $5}')
IP=$(ip addr show $INTERFACE | grep -w inet | awk '{ print $2}' | cut -d "/" -f1)
fi
hostName="${hostName:-"edf-installer.hpe.com"}"
clusterName=$(echo ${hostName} | cut -d '.' -f 1)
runMaprImage() {
echo "Please enter the local sudo password for $(whoami)"
sudo rm -rf /tmp/maprdemo
sudo mkdir -p /tmp/maprdemo/hive /tmp/maprdemo/zkdata /tmp/maprdemo/pid /tmp/maprdemo/logs /tmp/maprdemo/nfs
sudo chmod -R 777 /tmp/maprdemo/hive /tmp/maprdemo/zkdata /tmp/maprdemo/pid /tmp/maprdemo/logs /tmp/maprdemo/nfs
PORTS=' -p 2222:22 -p 7221:7221 -p 5660:5660 -p 8443:8443 -p 8080:8080 -p 8188:8188 -p 7222:7222 -p 5181:5181 -p 5692:5692 -p 5724:5724 -p 5756:5756 '
#export MAPR_EXTERNAL="0.0.0.0"
#incase non-mac ipconfig command would not be found
which ipconfig &>/dev/null
if [ $? -eq 0 ]; then
export MAPR_EXTERNAL=$(ipconfig getifaddr $INTERFACE)
else
export MAPR_EXTERNAL=$(ip addr show $INTERFACE | grep -w inet | awk '{ print $2}' | cut -d "/" -f1)
fi
if [ "${PUBLICIPV4DNS}" == "" ]; then
echo ""
else
export PUBLICIPV4DNS="${PUBLICIPV4DNS}"
fi
$container_engine pull ${IMAGE};
$container_engine run -d --privileged -v /tmp/maprdemo/zkdata:/opt/mapr/zkdata -v /tmp/maprdemo/pid:/opt/mapr/pid -v /tmp/maprdemo/logs:/opt/mapr/logs -v /tmp/maprdemo/nfs:/mapr $PORTS -e MAPR_EXTERNAL -e clusterName -e isSecure --hostname ${clusterName} ${IMAGE} > /dev/null 2>&1
# Check if container is started wihtout any issue
sleep 5 # wait for container to start
CID=$($container_engine ps -a | grep edf-seed-container | awk '{ print $1 }' )
RUNNING=$($container_engine inspect --format="{{.State.Running}}" $CID 2> /dev/null)
ERROR=$($container_engine inspect --format="{{.State.Error}}" $CID 2> /dev/null)
if [ "$RUNNING" == "true" -a "$ERROR" == "" ]
then
echo "Developer Sandbox Container $CID is running.."
else
echo "Failed to start Developer Sandbox Container $CID. Error: $ERROR"
exit
fi
}
$container_engine ps -a | grep edf-seed-container > /dev/null 2>&1
if [ $? -ne 0 ]
then
STATUS='NOTRUNNING'
else
echo "MapR sandbox container is already running."
echo "1. Kill the earlier run and start a fresh instance"
echo "2. Reconfigure the client and the running container for any network changes"
echo -n "Please enter choice 1 or 2 : "
read ANS
if [ "$ANS" == "1" ]
then
CID=$($container_engine ps -a | grep edf-seed-container | awk '{ print $1 }' )
$container_engine stop $CID > /dev/null 2>&1
$container_engine kill $CID > /dev/null 2>&1
$container_engine rm -f $CID > /dev/null 2>&1
STATUS='NOTRUNNING'
else
STATUS='RUNNING'
fi
fi
if [ "$STATUS" == "RUNNING" ]
then
# There is an instance of dev-sandbox-container. Check if it is running or not.
CID=$($container_engine ps -a | grep edf-seed-container | awk '{ print $1 }' )
RUNNING=$($container_engine inspect --format="{{.State.Running}}" $CID 2> /dev/null)
if [ "$RUNNING" == "true" ]
then
# Container is running there.
# Change the IP in /etc/hosts and reconfigure client for the IP Change
# Change the server side settings and restart warden
grep ${hostName} /etc/hosts | grep ${IP} > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "Please enter the local sudo password for $(whoami)"
sudo sed -i '/'${hostName}'/d' /etc/hosts &>/dev/null
sudo sh -c "echo \"${IP} ${hostName} ${clusterName}\" >> /etc/hosts"
sudo sed -i '' '/'${hostName}'/d' /opt/mapr/conf/mapr-clusters.conf &>/dev/null
sudo /opt/mapr/server/configure.sh -c -C ${hostName} -N ${clusterName} > /dev/null 2>&1
# Change the external IP in the container
echo "Please enter the root password of the container 'mapr' "
ssh root@localhost -p 2222 " sed -i \"s/MAPR_EXTERNAL=.*/MAPR_EXTERNAL=${IP}/\" /opt/mapr/conf/env.sh "
echo "Please enter the root password of the container 'mapr' "
ssh root@localhost -p 2222 "service mapr-warden restart"
fi
fi
if [ "$RUNNING" == "false" ]
then
# Container was started earlier but is not running now.
# Start the container. Change the client side settings
# Change the server side settings
$container_engine start ${CID}
echo "Please enter the local sudo password for $(whoami)"
sudo sed -i '/'${hostName}'/d' /etc/hosts &>/dev/null
sudo sh -c "echo \"${IP} ${hostName} ${clusterName}\" >> /etc/hosts"
sudo sed -i '' '/'${hostName}'/d' /opt/mapr/conf/mapr-clusters.conf &>/dev/null
sudo /opt/mapr/server/configure.sh -c -C ${hostName} -N ${clusterName} > /dev/null 2>&1
# Change the external IP in the container
echo "Please enter the root password of the container 'mapr' "
ssh root@localhost -p 2222 " sed -i \"s/MAPR_EXTERNAL=.*/MAPR_EXTERNAL=${IP}/\" /opt/mapr/conf/env.sh "
echo "Please enter the root password of the container 'mapr' "
ssh root@localhost -p 2222 "service mapr-warden restart"
fi
else
# There is no instance of dev-sandbox-container running. Start a fresh container and configure client.
runMaprImage
sudo sed -i '/'${hostName}'/d' /etc/hosts &>/dev/null
os_vers=`uname -s` > /dev/null 2>&1
`$container_engine cp $CID:/etc/environment /tmp/proxyseednode`
`echo "export SEED_NODE=true" >> /tmp/proxyseednode` > /dev/null 2>&1
if [ "$os_vers" == "Darwin" ]; then
if [ "${PROXYFILEDETAILS}" != "" ]; then
`cat $PROXYFILEDETAILS >>/tmp/proxyseednode` > /dev/null 2>&1
fi
fi
if [ "$os_vers" == "Linux" ] && [ "${PROXYFILEDETAILS}" != "" ]; then
`cat $PROXYFILEDETAILS >>/tmp/proxyseednode` > /dev/null 2>&1
fi
if [ "$os_vers" == "Linux" ] && [ "${PROXYFILEDETAILS}" == "" ]; then
`cat /etc/environment >>/tmp/proxyseednode` > /dev/null 2>&1
`cat /etc/profile.d/proxy.sh >>/tmp/proxyseednode` > /dev/null 2>&1
fi
`$container_engine cp /tmp/proxyseednode $CID:/etc/environment` > /dev/null 2>&1
`rm -rf /tmp/proxyseednode` > /dev/null 2>&1
services_up=0
sleep_total=600
sleep_counter=0
if [ "$os_vers" == "Darwin" ]; then
while [[ $sleep_counter -le $sleep_total ]]
do
curl -k -X GET "https://edf-installer.hpe.com:8443/rest/node/list?columns=svc" -u mapr:mapr123 &>/dev/null
if [ $? -ne 0 ];then
echo "services required for Ezmeral Data fabric are coming up"
sleep 60;
sleep_counter=$((sleep_counter+60))
else
services_up=1
break
fi
done
fi
if [ "$os_vers" == "Linux" ]; then
while [[ $sleep_counter -le $sleep_total ]]
do
curl -k -X GET https://`hostname -f`:8443/rest/node/list?columns=svc -u mapr:mapr123 &>/dev/null
if [ $? -ne 0 ];then
echo "services required for Ezmeral Data fabric are coming up"
sleep 60;
sleep_counter=$((sleep_counter+60))
else
services_up=1
break
fi
done
fi
if [ $services_up -eq 1 ]; then
echo
echo "Client has been configured with the $container_engine container."
echo
if [ "${PUBLICIPV4DNS}" == "" ]; then
echo "Please click on the link https://"${MAPR_EXTERNAL}":8443/app/dfui to deploy data fabric"
echo "For user documentation, see https://docs.ezmeral.hpe.com/datafabric/home/installation/installation_main.html"
echo
else
echo "Please click on the link https://"${PUBLICIPV4DNS}":8443/app/dfui to deploy data fabric"
echo "For user documentation, see https://docs.ezmeral.hpe.com/datafabric/home/installation/installation_main.html"
fi
else
echo
echo "services didnt come up in stipulated 10 mins time"
echo "please login to the container using ssh root@localhost -p 2222 with mapr as password and check further"
echo "For documentation on steps to debug, see https://docs.ezmeral.hpe.com/datafabric/home/installation/troubleshooting_seed_node_installation.html"
echo "once all services are up fabric UI is available at https://"${MAPR_EXTERNAL}":8443/app/dfui and fabrics can be deployed from that page"
echo
fi
fi