-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathcluster-manager.sh
executable file
·240 lines (219 loc) · 5.09 KB
/
cluster-manager.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
#!/bin/bash
#
# Written by Xueshan Feng <xueshan.feng@gmail.com>
#
# Init variables and sanity checks
export DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
function init() {
export PROJECTROOT=$DIR
export GITROOT=$DIR
export SCRIPTDIR=$GITROOT/scripts
[ -f $DIR/envs.sh ] && source $DIR/envs.sh
if [ ! -d $PROJECTROOT ];
then
echo "$PROJECTROOT doesn't exist."
exit 1
fi
aws --profile $AWS_PROFILE support help 2>/dev/null 1>&2
if [ $? = "255" ];
then
echo "Account $AWS_PROFILE doesn't exit."
exit 1
fi
# Update git repo
cd $GITROOT
git pull
}
#############
# Subroutines
#############
# Show all resources
function showAllResources() {
make show_all | more -R
}
# Make graph
function makeGraph() {
make graph && echo "Graphs are generated under build/graph directory."
}
function updateResource() {
make $resourceType -k 2>&1 | tee /tmp/$resourceType.$$.log
}
function createCluster() {
make all -k 2>&1 | tee /tmp/build.$$.log
}
function distroyCluster() {
make destroy_all -k 2>&1 | tee /tmp/destroy.$$.log
}
function hitAnyKey() {
echo -n "Hit any key to continue, or Ctl-C to cancel....."
read -n 1
clear
}
# Get confirmation for an action
function answerMe() {
answer='N'
echo -n "Are you sure to contiune? [Y/N]: "
read answer
echo ""
}
# Core display screen
function clusterScreen() {
echo "===== Cluster-Wide Operations ======"
echo ""
echo "0. Create Cluster"
echo "1. Destroy Cluster"
echo "2. Show all Resources"
echo "3. Make graph"
echo
echo "===== Update Individual Resources ======"
echo "10. Admiral"
echo "11. Worker"
echo "12. Etcd"
echo "13. Iam"
echo "14. Elastic loadbalancer: CI"
echo "15. Elastic loadbalancer: GitLab (WIP)"
echo "16. Elastic loadbalancer: dockerhub (WIP)"
echo "17. EFS"
echo "18. RDS"
echo "19. Route53"
echo "20. S3 buckets"
echo "21. VPC"
echo "88. Exit"
echo ""
echo "Note: If resources already exist, current status will be displayed."
echo -n "Please select one of the options above: "
read CHOICE
echo ""
case $CHOICE in
0)
createCluster
hitAnyKey
return $callAgain
;;
1)
distroyCluster
hitAnyKey
return $callAgain
;;
2)
showAllResources
hitAnyKey
return $callAgain
;;
3)
makeGraph
hitAnyKey
return $callAgain
;;
10)
resourceType='admiral'
updateResource
hitAnyKey
return $callAgain
;;
11)
resourceType='worker'
updateResource
hitAnyKey
return $callAgain
;;
12)
resourceType='etcd'
updateResource
hitAnyKey
return $callAgain
;;
13)
resourceType='iam'
updateResource
hitAnyKey
return $callAgain
;;
14)
resourceType='elb_ci'
updateResource
hitAnyKey
return $callAgain
;;
15)
resourceType='elb-gitlab'
updateResource
hitAnyKey
return $callAgain
;;
16)
resourceType='elb-dockerhub'
updateResource
hitAnyKey
return $callAgain
;;
17)
resourceType='efs'
updateResource
hitAnyKey
return $callAgain
;;
18)
resourceType='rds'
updateResource
hitAnyKey
return $callAgain
;;
19)
resourceType='route53'
updateResource
hitAnyKey
return $callAgain
;;
20)
resourceType='s3'
updateResource
hitAnyKey
return $callAgain
;;
21)
resourceType='vpc'
updateResource
hitAnyKey
return $callAgain
;;
88|q|quit|exit)
# Reminder to uppdate git repo
cd $GITROOT
if ! git diff-index --name-status --exit-code HEAD -- ; then \
echo "You have unpublished changes:"; exit 1 ; \
else
exit 0
fi
;;
*)
clear
return $callAgain
esac
}
################
# Main routine.
################
if [ ! -f "envs.sh" ];
then
echo "Please define required environment variables in envs.sh"
exit 1
fi
init
callAgain=99
status=$callAgain
while [ $status -eq $callAgain ]
do
clusterScreen
status=$?
clear
done
exit 0
DOCS=<<__END_OF_DOCS__
=head1 NAME
cluster-manager.sh - Menu-driven script to install CoreOS docker platform.
=head1 FILES
The script reads the platform configuration from envs.sh.
=head1 AUTHORS
Xueshan Feng <xueshan.feng@gmail.com>
=cut