-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmod_start_cluster
executable file
·47 lines (36 loc) · 1.4 KB
/
mod_start_cluster
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
#!/bin/bash
########
# Author: Ratish Maruthiyodan
# Project: Docker HDP Lab
# Description: Add-hoc script - To start all the nodes in the cluster. To be used with "all_node_start.sh"
########
start_instance(){
docker -H $SWARM_MANAGER:4000 start $INSTANCE_NAME
}
populate_hostsfile(){
IP=`docker -H $SWARM_MANAGER:4000 inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_NAME`
HOST_NAME=`docker -H $SWARM_MANAGER:4000 inspect --format='{{.Config.Hostname}}' $INSTANCE_NAME`
DOMAIN_NAME=`docker -H $SWARM_MANAGER:4000 inspect --format='{{.Config.Domainname}}' $INSTANCE_NAME`
echo $IP " " $HOST_NAME.$DOMAIN_NAME $HOST_NAME >> $TEMP_HOST_FILE
echo $IP $HOST_NAME.$DOMAIN_NAME $HOST_NAME
}
if [ $# -ne 1 ];then
echo "Usage:: start_cluster <USERNAME>-<CLUSTERNAME>"
exit
fi
source /etc/docker-hdp-lab.conf
USERNAME_CLUSTERNAME=$1
TEMP_HOST_FILE=/tmp/$USERNAME_CLUSTERNAME-tmphostfile
echo $USERNAME_CLUSTERNAME
### Starting the stopped Instances in the cluster and preparing /etc/hosts file on all the nodes again
echo "127.0.0.1 localhost" > $TEMP_HOST_FILE
for i in $(docker -H $SWARM_MANAGER:4000 ps -a | grep $USERNAME_CLUSTERNAME | awk -F "/" '{print $NF}')
do
INSTANCE_NAME=$i
if (! `docker -H $SWARM_MANAGER:4000 inspect -f {{.State.Running}} $INSTANCE_NAME` ) then
echo "Starting: " $INSTANCE_NAME
start_instance
fi
# populate_hostsfile
done
rm -f $TEMP_HOST_FILE