forked from rmaruthiyodan/docker-hdp-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-hdp-lab_service.sh
executable file
·102 lines (87 loc) · 2.55 KB
/
docker-hdp-lab_service.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
#!/bin/bash
########
# Author: Ratish Maruthiyodan
# Project: Docker HDP Lab
# Description: Script to start up the docker-hdp-cluster on every Docker Host
########
#set -x
start() {
if [ ! -f "/etc/docker-hdp-lab.conf" ]
then
echo -e "\nFile not Found: \"/etc/docer-hdp-lab.conf\"".
echo -e "Copy the file \"docker-hdp-lab.conf\" to /etc/ and configure it, and run the setup script first\n"
exit 1
fi
source /etc/docker-hdp-lab.conf
# Disabling vm.swappiness
echo 0 > /proc/sys/vm/swappiness
# Disabling THP
echo "never" > /sys/kernel/mm/transparent_hugepage/enabled
echo "never" > /sys/kernel/mm/transparent_hugepage/defrag
# Enabling ip_forward
echo "1" > /proc/sys/net/ipv4/ip_forward
if [ $SWARM_MANAGER == $HOSTNAME ]
then
docker ps -a | grep -q "consul"
CONSUL_present=$?
docker ps -a | grep -q "swarm_manager"
SM_present=$?
docker ps -a | grep -q "swarm_join"
SJ_present=$?
docker ps -a | grep -q "overlay-gatewaynode"
OG_present=$?
if [ "$CONSUL_present" -ne 0 ] || [ "$SM_present" -ne 0 ] || [ "$SJ_present" -ne 0 ] || [ "$OG_present" -ne 0 ]
then
echo "Execute the setup script before starting the Docker-HDP-Cluster"
exit 1
fi
echo -e "\nStarting Consul Instance..."
docker start consul
sleep 20
echo -e "\nStarting Swarm Manager Instance..."
docker start swarm_manager
sleep 10
echo -e "\nStarting Swarm Join Instance..."
docker start swarm_join
echo -e "\nStarting Overlay Network Gateway Instance..."
docker start overlay-gatewaynode
fi
if [ $LOCAL_REPO_NODE == $HOSTNAME ]
then
docker ps -a | grep -q "localrepo"
LOCALREPO_present=$?
if [ "$LOCALREPO_present" -ne 0 ]
then
echo "Execute the setup script on this node before starting the Docker-HDP-Cluster"
exit 1
fi
docker start localrepo
fi
docker ps | grep -q swarm_join
if [ $? -ne 0 ]
then
echo -e "\nStarting Swarm Join Instance..."
docker start swarm_join
fi
route -n | grep -q $(echo $OVERLAY_NETWORK | awk -F "/" '{print $1}')
if [ $? -ne 0 ]
then
echo "Adding Route Entry to reach Overlay network:: "
if [ $SWARM_MANAGER == $HOSTNAME ]
then
echo "route add -net $OVERLAY_NETWORK gw $(docker -H $SWARM_MANAGER:4000 exec overlay-gatewaynode hostname -i | awk '{print $2}')"
route add -net $OVERLAY_NETWORK gw $(docker -H $SWARM_MANAGER:4000 exec overlay-gatewaynode hostname -i | awk '{print $2}')
else
echo "route add -net $OVERLAY_NETWORK gw $SWARM_MANAGER"
route add -net $OVERLAY_NETWORK gw $SWARM_MANAGER
fi
fi
exit 0
}
stop() {
docker kill $(docker ps -q)
exit 0
}
case $1 in
start|stop) "$1" ;;
esac