-
Notifications
You must be signed in to change notification settings - Fork 0
/
wakame-vdc-install-hierarchy.sh
739 lines (597 loc) · 14.5 KB
/
wakame-vdc-install-hierarchy.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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
#!/bin/bash
reportfail()
{
echo "Failed...exiting. ($*)" 1>&2
exit 255
}
try()
{
eval "$@" || reportfail "$@"
}
[ "root" = "$(whoami)" ] || reportfail "must be root"
default_steps='
all_steps
'
######## fake step: all_steps
# The purpose of this step is to give
# one target that summarizes all the
# tree/DAGs of steps in this file.
deps_all_steps='
start_wakame_vdc
'
check_all_steps()
{
false
}
do_all_steps()
{
false
}
######## fake step: block
# The purpose of this steps is so that it can
# be added to other fake steps to block them
# from trying to "do" their dependencies.
deps_block='
'
check_block()
{
false
}
do_block()
{
false
}
######## confirm_bridge_already_setup
# the check_ part must be run
deps_confirm_bridge_already_setup='
'
check_confirm_bridge_already_setup()
{
get_default_route && get_ip_mask "$INTERFACE"
(
set -e
which brctl >/dev/null
[ "$INTERFACE" = "br0" ]
) || {
echo
echo "This script requires the bridge to be set up first,"
echo "which should be done manually. A script to do this"
echo "has been prepared at /tmp/setup-bridge.sh, assuming"
echo "IP=$IPADDR, MASK=$MASK, GATEWAY=$GATEWAY and"
echo "that the outgoing interface is $INTERFACE. Inspect"
echo "the script carefully for correctness before running."
cat >/tmp/setup-bridge.sh <<EOF
set -x
yum install -y bridge-utils
which brctl || exit 255
cat > /etc/sysconfig/network-scripts/ifcfg-br0 <<EOF2
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes
NM_CONTROLLED=no
IPADDR=$IPADDR
NETMASK=$MASK
GATEWAY=$GATEWAY
DNS1=8.8.8.8
DELAY=0
EOF2
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF2
DEVICE="$INTERFACE"
ONBOOT="yes"
BRIDGE=br0
NM_CONTROLLED=no
EOF2
set +x
echo "Will reset networking after 15 seconds"
echo "Press ^C to cancel."
set -x
sleep 15
service network restart
EOF
chmod +x /tmp/setup-bridge.sh
return 255
} 1>&2
}
do_confirm_bridge_already_setup()
{
:
}
get_default_route()
{
while read iface dest gway rest; do
if [ "$dest" = "00000000" ]; then
export INTERFACE="$iface"
export GATEWAY="$gway"
break
fi
done </proc/net/route
[ "$GATEWAY" = "" ] && return 255
GATEWAY="$({ read -n 2 dd; read -n 2 cc; read -n 2 bb; read -n 2 aa
echo "$(( 0x$aa )).$(( 0x$bb )).$(( 0x$cc )).$(( 0x$dd ))"
} <<<"$GATEWAY" )"
}
get_ip_mask()
{
iface="$1"
cmdout="$(ifconfig "$iface")"
read IPADDR ignore <<<"${cmdout#*inet addr:}"
read MASK ignore <<<"${cmdout#*Mask:}"
}
get_ip_prefix()
{
iface="$1"
cmdout="$(ip addr show "$iface")"
IFS=" /" read IPADDR PREFIX ignore <<<"${cmdout#*inet }"
}
######## lets_get_started
deps_lets_get_started='
install_dcmgr
install_hva
install_webui
'
check_lets_get_started()
{
[ -f /tmp/did_lets_get_started ]
}
do_lets_get_started()
{
# just a wrapper to call the deps
touch /tmp/did_lets_get_started
}
######## yum_repository_setup
deps_yum_repository_setup='
'
check_yum_repository_setup()
{
#[ -f /etc/yum.repos.d/openvz.repo ] && \
[ -f /etc/yum.repos.d/wakame-vdc.repo ] && \
[ -f /etc/yum.repos.d/epel.repo ] && \
[ -f /etc/yum.repos.d/epel-testing.repo ]
}
do_yum_repository_setup()
{
curl -o /etc/yum.repos.d/wakame-vdc.repo -R https://raw.githubusercontent.com/axsh/wakame-vdc/master/rpmbuild/wakame-vdc.repo
# curl -o /etc/yum.repos.d/openvz.repo -R https://raw.githubusercontent.com/axsh/wakame-vdc/master/rpmbuild/openvz.repo
# yum install -y epel-release && touch /tmp/installed_epel_release
# from https://github.com/wakameci/buildbook-rhel6/blob/master/epel-release/xexecscript.d/epel-release.sh
rpm -Uvh http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/6/i386/epel-release-6-8.noarch.rpm
# workaround 2014/10/17
#
# in order escape below error
# > Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again
#
sed -i \
-e 's,^#baseurl,baseurl,' \
-e 's,^mirrorlist=,#mirrorlist=,' \
-e 's,http://download.fedoraproject.org/pub/epel/,http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/,' \
/etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel-testing.repo
}
######## install_dcmgr
deps_install_dcmgr='
yum_repository_setup
'
check_install_dcmgr()
{
[ -f /tmp/installed_dcmgr ]
}
do_install_dcmgr()
{
yum install -y wakame-vdc-dcmgr-vmapp-config && \
touch /tmp/installed_dcmgr
}
######## install_hva
deps_install_hva='
yum_repository_setup
'
check_install_hva()
{
[ -f /tmp/installed_hva ]
}
do_install_hva()
{
yum install -y wakame-vdc-hva-kvm-vmapp-config && touch /tmp/installed_hva
}
######## install_webui
deps_install_webui='
yum_repository_setup
'
check_install_webui()
{
[ -f /tmp/installed_webui ]
}
do_install_webui()
{
yum install -y wakame-vdc-webui-vmapp-config && touch /tmp/installed_webui
}
######## configuration
deps_configuration='
lets_get_started
service_configs
create_vdc_database
register_hva
register_image
register_network
configure_gui
'
check_configuration()
{
[ -f /tmp/did_configuration ]
}
do_configuration()
{
touch /tmp/did_configuration
}
######## service_configs
deps_service_configs='
'
service_config_files=(
/opt/axsh/wakame-vdc/dcmgr/config/dcmgr.conf.example:/etc/wakame-vdc/dcmgr.conf
/opt/axsh/wakame-vdc/dcmgr/config/hva.conf.example:/etc/wakame-vdc/hva.conf
/opt/axsh/wakame-vdc/frontend/dcmgr_gui/config/database.yml.example:/etc/wakame-vdc/dcmgr_gui/database.yml
/opt/axsh/wakame-vdc/frontend/dcmgr_gui/config/dcmgr_gui.yml.example:/etc/wakame-vdc/dcmgr_gui/dcmgr_gui.yml
/opt/axsh/wakame-vdc/frontend/dcmgr_gui/config/instance_spec.yml.example:/etc/wakame-vdc/dcmgr_gui/instance_spec.yml
/opt/axsh/wakame-vdc/frontend/dcmgr_gui/config/load_balancer_spec.yml.example:/etc/wakame-vdc/dcmgr_gui/load_balancer_spec.yml
)
check_service_configs()
{
for f in "${service_config_files[@]}" ; do
[ -f "${f#*:}" ] || return 255
done
return 0
}
do_service_configs()
{
for f in "${service_config_files[@]}" ; do
cp "${f%:*}" "${f#*:}"
done
}
######## create_vdc_database
deps_create_vdc_database='
'
check_create_vdc_database() {
[ -f /tmp/created_vdc_database ]
}
do_create_vdc_database()
{
service mysqld start
mysqladmin -uroot create wakame_dcmgr
cd /opt/axsh/wakame-vdc/dcmgr
/opt/axsh/wakame-vdc/ruby/bin/rake db:up || return
touch /tmp/created_vdc_database
}
######## register_hva
deps_register_hva='
'
check_register_hva()
{
[ -f /tmp/did_register_hva ]
}
do_register_hva()
{
uncomment 'NODE_ID=demo1' '/etc/default/vdc-hva' || return
/opt/axsh/wakame-vdc/dcmgr/bin/vdc-manage host add hva.demo1 \
--uuid hn-demo1 \
--display-name "demo HVA 1" \
--cpu-cores 100 \
--memory-size 10240 \
--hypervisor kvm \
--arch x86_64 \
--disk-space 102400 \
--force || return
touch /tmp/did_register_hva
}
function uncomment() {
local commented_line=$1
local files=$2
sudo sed -i -e "s/^#\\(${commented_line}\\)/\\1/" ${files}
}
######## download_image
deps_download_image='
'
check_download_image()
{
[ -f /var/lib/wakame-vdc/images/ubuntu-lucid-kvm-md-32.raw.gz ]
}
do_download_image()
{
sudo mkdir -p /var/lib/wakame-vdc/images
(
cd /var/lib/wakame-vdc/images
sudo curl -O http://dlc.wakame.axsh.jp.s3.amazonaws.com/demo/vmimage/ubuntu-lucid-kvm-md-32.raw.gz
)
}
######## register_image
deps_register_image='
download_image
'
check_register_image()
{
[ -f /tmp/register_image ]
}
do_register_image()
{
/opt/axsh/wakame-vdc/dcmgr/bin/vdc-manage backupstorage add \
--uuid bkst-local \
--display-name "local storage" \
--base-uri "file:///var/lib/wakame-vdc/images/" \
--storage-type local \
--description "storage on the local filesystem" || return
/opt/axsh/wakame-vdc/dcmgr/bin/vdc-manage backupobject add \
--uuid bo-lucid5d \
--display-name "Ubuntu 10.04 (Lucid Lynx) root partition" \
--storage-id bkst-local \
--object-key ubuntu-lucid-kvm-md-32.raw.gz \
--size 149084 \
--allocation-size 359940 \
--container-format gz \
--checksum 1f841b195e0fdfd4342709f77325ce29 || return
/opt/axsh/wakame-vdc/dcmgr/bin/vdc-manage image add local bo-lucid5d \
--account-id a-shpoolxx \
--uuid wmi-lucid5d \
--root-device uuid:148bc5df-3fc5-4e93-8a16-7328907cb1c0 \
--display-name "Ubuntu 10.04 (Lucid Lynx)"
touch /tmp/register_image
}
######## register_network
deps_register_network='
'
check_register_network()
{
[ -f /tmp/register_network ]
}
do_register_network()
{
(
set -e
get_default_route
get_ip_prefix "$INTERFACE"
/opt/axsh/wakame-vdc/dcmgr/bin/vdc-manage network add \
--uuid nw-demo1 \
--ipv4-network $IPADDR \
--prefix $PREFIX \
--ipv4-gw $GATEWAY \
--dns 8.8.8.8 \
--account-id a-shpoolxx \
--display-name "demo network"
guess_unused="${IPADDR%.*}.100 ${IPADDR%.*}.150"
/opt/axsh/wakame-vdc/dcmgr/bin/vdc-manage network dhcp addrange nw-demo1 $guess_unused
# /opt/axsh/wakame-vdc/dcmgr/bin/vdc-manage network reserve nw-demo1 --ipv4 192.168.3.100
/opt/axsh/wakame-vdc/dcmgr/bin/vdc-manage macrange add 525400 1 ffffff --uuid mr-demomacs
/opt/axsh/wakame-vdc/dcmgr/bin/vdc-manage network dc add public --uuid dcn-public --description "the network instances are started in"
/opt/axsh/wakame-vdc/dcmgr/bin/vdc-manage network dc add-network-mode public securitygroup
/opt/axsh/wakame-vdc/dcmgr/bin/vdc-manage network forward nw-demo1 public
)
touch /tmp/register_network
}
######## configure_gui
deps_configure_gui='
'
check_configure_gui()
{
[ -f /tmp/configure_gui ]
}
do_configure_gui()
{
(
set -e
mysqladmin -uroot create wakame_dcmgr_gui
cd /opt/axsh/wakame-vdc/frontend/dcmgr_gui/
/opt/axsh/wakame-vdc/ruby/bin/rake db:init
/opt/axsh/wakame-vdc/frontend/dcmgr_gui/bin/gui-manage account add --name default --uuid a-shpoolxx
/opt/axsh/wakame-vdc/frontend/dcmgr_gui/bin/gui-manage user add --name "demo user" --uuid u-demo --password demo --login-id demo
/opt/axsh/wakame-vdc/frontend/dcmgr_gui/bin/gui-manage user associate u-demo --account-ids a-shpoolxx
)
touch /tmp/configure_gui
}
######## start_required_services
deps_start_required_services='
'
check_start_required_services()
{
{
service rabbitmq-server status || return
service mysqld start || return
} 2>/dev/null >&2
}
do_start_required_services()
{
service rabbitmq-server start
service mysqld start
}
######## start_wakame_vdc
deps_start_wakame_vdc='
confirm_bridge_already_setup
configuration
start_required_services
'
wakame_jobs=(
vdc-dcmgr
vdc-collector
vdc-hva
vdc-webui
)
check_start_wakame_vdc()
{
for j in "${wakame_jobs[@]}"; do
[[ "$(status $j 2>/dev/null)" == *running* ]] || return 255
done
return 0
}
do_start_wakame_vdc()
{
for j in "${wakame_jobs[@]}"; do
start $j
done
}
reset_start_wakame_vdc()
{
for j in "${wakame_jobs[@]}"; do
stop $j
done
}
######################### dispatching code ################################
# {do/check/do1/check1/reset1} {list of steps....} -- params
main()
{
try abspath="$(cd $(dirname "$0") ; pwd )"
try cd "$abspath"
case "$1" in
check | check1 | 'do' | do1 | reset1)
cmd="$1"
shift
;;
*)
cmd=check
;;
esac
# split remaining params into those before "--" and those after (if any).
steplist=() # installation/demo steps to process
while [ "$#" != 0 ]
do
p="$1" ; shift
[ "$p" = "--" ] && break
func_defined "check_$p" || return
func_defined "do_$p" || return
steplist=( "${steplist[@]}" "$p" )
done
paramlist=() # params taken one by one by interactive prompts, for one-line shortcuts
while [ "$#" != 0 ]
do
p="$1" ; shift
paramlist=( "${paramlist[@]}" "$p" )
done
[ "${#steplist[@]}" = 0 ] && steplist=( $default_steps )
for step in "${steplist[@]}"
do
echo
echo "================= ${cmd}_cmd" "$step"
"${cmd}_cmd" "$step"
done
}
read_or_param()
{
if [ "${#paramlist[@]}" = 0 ]
then
read val
else
val="${paramlist[0]}"
paramlist=("${paramlist[@]:1}") # shift array
echo "(from cmdline): $val"
fi
}
func_defined()
{
if ! declare -f "$1" > /dev/null # function defined?
then
echo "Function for step not found: $1" 1>&2
return 1
fi
return 0
}
check1_cmd()
{
try cd "$abspath"
local stepname="$1"
local indent="$2"
printf "*%-10s %s " "${indent// -- /*}" "$indent$stepname"
if "check_$stepname"
then
echo "Done (maybe)"
else
echo "Not Done"
fi
}
already_checked=""
: ${dedup:=yes}
: ${dotout:=/tmp/vnet.dot}
check_cmd()
{
local stepname="$1"
local indent="$2"
local dotlevel="$dotlevel"
local depstep
if [ "$dotout" != "" ]; then
if [ "$dotlevel" = "" ]; then
exec 44>"$dotout"
echo "strict digraph { " >&44
dotlevel=1
else
dotlevel=$(( dotlevel + 1 ))
fi
fi
check1_cmd "$stepname" "$indent"
if [ "$dedup" = "yes" ]; then
tmp="${already_checked//$stepname/}"
[[ "$tmp" == *,,* ]] && return
already_checked="$already_checked ,$stepname, "
fi
# uncomment to have the step source inserted in output
# eval type "do_${stepname}"
local deps
eval 'deps=$deps_'"$stepname"
for depstep in $deps
do
check_cmd "$depstep" "$indent -- "
[ "$dotout" = "" ] && continue
echo "$depstep -> $stepname" >&44
done
if [ "$dotout" != "" ] && [ "$dotlevel" = "1" ]; then
echo "}" >&44
else
dotlevel=$(( dotlevel - 1 ))
fi
}
reset1_cmd()
{
local stepname="$1"
local indent="$2"
echo -n "$indent$stepname "
if "reset_$stepname"
then
echo "Maybe reset."
else
echo "Probably did not reset."
exit 255
fi
}
do1_cmd()
{
try cd "$abspath"
local stepname="$1"
local indent="$2"
printf "*%-10s %s " "${indent// -- /*}" "$indent$stepname"
#echo -n "$indent$stepname "
echo
if "do_$stepname"
then
if "check_$stepname"
then
echo "Success."
else
echo "Ran but failed check....exiting."
exit 255
fi
else
echo "Failed....exiting." 1>&2
exit 255
fi
}
do_cmd()
{
local stepname="$1"
local indent="$2"
if "check_$stepname"
then
echo "$indent$stepname :: Probably already done"
return 0
fi
local deps
eval 'deps=$deps_'"$stepname"
for depstep in $deps
do
do_cmd "$depstep" "$indent -- "
done
do1_cmd "$stepname" "$indent"
}
main "$@"