-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.sh
executable file
·1038 lines (848 loc) · 28.6 KB
/
run.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
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /bin/bash
## Manages the building, cleaning and deployment of Opencast from this machine
## Uses:
## - Ansible
## - Git
## - Maven
## - xmlstarlet
## - sshpass
# Original (2016-06-27): Corne Oosthuizen
# See: changelog.md
source config-dist.sh
# internal configuration
CONFIG_DIR="config"
SRC_VERSION=$(xmlstarlet sel -t -v "/_:project/_:version" $SRC/pom.xml)
DEPLOY_TYPE="dev"
HOSTS_FILE=$HOSTS_FOLDER"dev"
CURRENT_USER=$(logname)
# action variables (what we will do)
BUILD=false
CLEAN=false
DEPLOY=false
FORCE_DEPLOY=false
LTI=false
LIST=false
UPDATE=false
RECONFIGURE=false
ROLLBACK=false
STATUS=false
STARTUP=false
STOP=false
VERSION=false
ALIAS=false
TEST=false
TRACK4K=false
TRIMPOINT=false
EMPTYVENUE=false
OCR=false
SOX=false
ACTIONS=0
# list of servers to use
declare -a ACTIVE_LIST
# should we execute permanent scripts
LIVE=true
setStatus() {
branch_name=$(git -C $SRC symbolic-ref -q HEAD)
branch_name=${branch_name##refs/heads/}
branch_name=${branch_name:-HEAD}
echo "src: $SRC" > $STATUS_FILE
echo >> $STATUS_FILE
git -C $SRC status | grep $branch_name >> $STATUS_FILE
echo "" >> $STATUS_FILE
git -C $SRC show --oneline | head -n 1 >> $STATUS_FILE
echo "" >> $STATUS_FILE
}
showServers() {
cd $YML
if [ -f $HOSTS_FILE ]; then
echo " Servers ($HOSTS_FILE):"
while read -r line
do
echo " $line"
done < $HOSTS_FILE
else
echo " ERROR: No servers defined!"
fi
echo
echo " Servers ($HOSTS_FILE):"
for name in "${ACTIVE_SERVER_LIST[@]}"; do
echo " $name"
done
echo
}
displayTime() {
T=$1
D=$((T/60/60/24))
H=$((T/60/60%24))
M=$((T/60%60))
S=$((T%60))
[ $D -ge 1 ] && printf '%d d ' $D
[ $H -ge 1 ] && printf '%d h ' $H
[ $M -ge 1 ] && printf '%d m ' $M
printf '%d sec\n' $S
}
writeConfiguration() {
INPUT=$1
OUTPUT=$2
while read line
do
[[ $line = \#* ]] && continue
if [ ! -z "$line" ]; then
IFS="=" read find replace <<< "$line"
sed -i -e "/#.*/! s;$find;$replace;" $OUTPUT
fi
done < $INPUT
}
packageConfigurationFile() {
name=$1
filename=$2
out=$3
build_file="$FILES/config/build-$name.cfg"
if [ ! -f "$build_file" ]; then
echo "deploy_server_name=http://$name.uct.ac.za:8080" > $build_file
echo "deploy_server_nodename=$name.uct.ac.za" > $build_file
echo "" > $build_file
fi
# replace the server specific settings
writeConfiguration $build_file $file
# replace generic
writeConfiguration $FILES/config/build-default.cfg $file
if $out; then
printf "."
fi
}
packageConfiguration() {
name=$1
tmp="$TMP_DIR/$name"
if [ "$CONFIG_DIR" != "$name" ]; then
# make sure that the files exist for the server so that packaging them is easier next time
cfg_dir="$FILES/config/$name"
cfg_file="$FILES/config/conf-$name.cfg"
build_file="$FILES/config/build-$name.cfg"
if [ ! -f "$cfg_file" ]; then
cp "$FILES/conf-server.template" "$cfg_file"
sed -i -e "/#.*/! s;NNNN;$name;" "$cfg_file"
fi
if [ ! -f "$build_file" ]; then
echo "deploy_server_name=http://$name.uct.ac.za:8080" > $build_file
echo "deploy_server_nodename=$name.uct.ac.za" > $build_file
echo "" > $build_file
fi
if [ ! -d "$cfg_dir" ]; then
mkdir -p "$cfg_dir/etc"
mkdir -p "$cfg_dir/bin"
touch "$cfg_dir/etc/.keep"
touch "$cfg_dir/bin/.keep"
fi
mkdir -p $tmp
# copy default configuration files to tmp
cp -r $FILES/config/default/* $tmp
# overwrite with server specific configuration files
cp -r $FILES/config/$name/* $tmp
for file in $(find $tmp -type f -type f -not -name ".keep" -not -name "*.jks" -not -name "*.swp")
do
packageConfigurationFile $name $file false &
done
wait
cd $tmp
tar -zcpf $FILES/config/conf-$name.tar.gz .
rm -rf $tmp
printf "."
fi
}
require_clean_work_tree () {
local __result=$1
local __desc=$2
local __msg=""
local valid=true
local err=0
#git fetch
git rev-parse --verify HEAD >/dev/null || exit 1
git update-index -q --ignore-submodules --refresh
if ! git diff-files --quiet --ignore-submodules
then
msg="$__desc has unstaged changes."
err=1
fi
if ! git diff-index --cached --quiet --ignore-submodules HEAD --
then
msg="$__desc contains uncommitted changes."
err=1
fi
if [ $err = 0 ]; then
err=`git ls-files --exclude-standard --others| wc -l`
if [ $err = 1 ]; then
msg="$__desc contains untracked files ($err)."
fi
fi
if [ $err = 1 ]; then
# valid=false
echo " $msg"
fi
eval $__result="'$valid'"
}
# Get the display name of the user
# params:
# $1 -- the section (if any)
# $2 -- the key
getCurrentUser() {
section="users"
key=$CURRENT_USER
value=$(
if [ -n "$section" ]; then
sed -n "/^\[$section\]/, /^\[/p" $DEPLOY_CFG_FOLDER/users.cfg
else
cat $DEPLOY_CFG_FOLDER/users.cfg
fi |
egrep "^ *\b$key\b *=" |
head -1 | cut -f2 -d'=' |
sed 's/^[ "'']*//g' |
sed 's/[ ",'']*$//g' )
if [ -n "$value" ]; then
echo $value
return
else
echo $key
return
fi
}
addDeploymentMarker() {
local production=$1
local type=$2
local gitlog=$3
local branch=$4
if $NEWRELIC_USE && $production; then
printf "Set deploy marker: "
result=$(curl --write-out '%{http_code}' --silent --output /dev/null -X POST "https://api.newrelic.com/v2/applications/$NEWRELIC_APP/deployments.json" \
-H "X-Api-Key:$NEWRELIC_API" -i \
-H 'Content-Type: application/json' \
-d \
"{
\"deployment\": {
\"revision\": \"$branch\",
\"changelog\": \"$DEPLOY_TYPE-$type\",
\"description\": \"$gitlog\",
\"user\": \"$(getCurrentUser)\"
}
}")
if [ $result = "201" ]; then
echo "done"
else
echo "error [$result]"
fi
echo
fi
}
main() {
echo #$ACTIONS
printf "Actions [$DEPLOY_TYPE]($SRC_VERSION): "
$UPDATE && printf "Update"
$UPDATE && [ "$ACTIONS" -gt "1" ] && printf " - " && ACTIONS=$((ACTIONS-1))
$BUILD && printf "Build"
$BUILD && [ "$ACTIONS" -gt "1" ] && printf " - " && ACTIONS=$((ACTIONS-1))
$CLEAN && printf "Clean"
$CLEAN && [ "$ACTIONS" -gt "1" ] && printf " - " && ACTIONS=$((ACTIONS-1))
# if we are deploying then don't do reconfigure or rollback
if [[ $DEPLOY == true && ( $RECONFIGURE == true || $ROLLBACK == true ) ]]; then
$RECONFIGURE && ACTIONS=$((ACTIONS-1))
$ROLLBACK && ACTIONS=$((ACTIONS-1))
RECONFIGURE=false
ROLLBACK=false
fi
# if we rollback then we can't deploy or reconfigure
if [[ $RECONFIGURE == true && $ROLLBACK == true ]]; then
$DEPLOY && ACTIONS=$((ACTIONS-1))
$RECONFIGURE && ACTIONS=$((ACTIONS-1))
DEPLOY=false
RECONFIGURE=false
fi
$DEPLOY && printf "Deploy"
$DEPLOY && [ "$ACTIONS" -gt "1" ] && printf " - " && ACTIONS=$((ACTIONS-1))
$RECONFIGURE && printf "Reconfigure"
$RECONFIGURE && [ "$ACTIONS" -gt "1" ] && printf " - " && ACTIONS=$((ACTIONS-1))
$ROLLBACK && printf "Rollback"
$ROLLBACK && [ "$ACTIONS" -gt "1" ] && printf " - " && ACTIONS=$((ACTIONS-1))
$LTI && printf "Deploy LTI Tool"
$LTI && [ "$ACTIONS" -gt "1" ] && printf " - " && ACTIONS=$((ACTIONS-1))
$VERSION && printf "Check dependencies"
$VERSION && [ "$ACTIONS" -gt "1" ] && printf " - " && ACTIONS=$((ACTIONS-1))
$STOP && printf "Stop Services"
$STOP && [ "$ACTIONS" -gt "1" ] && printf " - " && ACTIONS=$((ACTIONS-1))
$STARTUP && printf "Start Services"
$STARTUP && [ "$ACTIONS" -gt "1" ] && printf " - " && ACTIONS=$((ACTIONS-1))
$ALIAS && printf "Deploy Bash Aliases"
$ALIAS && [ "$ACTIONS" -gt "1" ] && printf " - " && ACTIONS=$((ACTIONS-1))
$TEST && printf "Run Dependency Test"
$TEST && [ "$ACTIONS" -gt "1" ] && printf " - " && ACTIONS=$((ACTIONS-1))
$TRACK4K && printf "Deploy Track4K"
$TRACK4K && [ "$ACTIONS" -gt "1" ] && printf " - " && ACTIONS=$((ACTIONS-1))
$TRIMPOINT && printf "Deploy Audio trimpoint detection"
$TRIMPOINT && [ "$ACTIONS" -gt "1" ] && printf " - " && ACTIONS=$((ACTIONS-1))
$EMPTYVENUE && printf "Deploy Empty Venue detection"
$EMPTYVENUE && [ "$ACTIONS" -gt "1" ] && printf " - " && ACTIONS=$((ACTIONS-1))
$OCR && printf "Deploy Tesseract and Hunspell data"
$OCR && [ "$ACTIONS" -gt "1" ] && printf " - " && ACTIONS=$((ACTIONS-1))
$SOX && printf "Deploy Sox"
$SOX && [ "$ACTIONS" -gt "1" ] && printf " - " && ACTIONS=$((ACTIONS-1))
if $LIST && $( ! $STATUS); then
printf "Display List Servers"
[ "$ACTIONS" -gt "1" ] && printf " - " && ACTIONS=$((ACTIONS-1))
fi
$STATUS && printf "Show Current Status"
echo
echo
start_time=`date +%s`
compiled=1
if [[ $DEPLOY_TYPE = "prod" ]]; then
production=true
else
production=false
fi
# OC source gitlog and branch
gitlog=$(git -C $SRC show --oneline | head -n 1)
branch=$(git -C $SRC rev-parse --symbolic-full-name --abbrev-ref HEAD)
cd $SRC
require_clean_work_tree valid_src "Source ($SRC)"
$(! $valid_src) && echo
cd $YML
require_clean_work_tree valid_script "Script ($YML)"
$(! $valid_script) && echo
# should be first
if $UPDATE; then
echo "Updating opencast build ..."
git -C $SRC fetch && git -C $SRC pull
echo
fi
# should be second before displaying status
if $BUILD; then
st=$(date +'%Y-%m-%d.%H-%M-%S')
log_file=$YML"/log/oc-build."$st".log"
now=$(date +'%Y-%m-%d %H:%M:%S')
target=$(date --date='3 minutes' +'%Y-%m-%d %H:%M:%S')
# the source is valid or we are just doing dev in which case
# build source
if [[ $valid_src == true || $DEPLOY_TYPE == "dev" ]]; then
echo "Building source: "
echo " mvn -T 1C clean install -Dmaven.test.skip=true (takes around 3min)"
echo " $now : Started"
echo " $target : Target"
if $LIVE; then
cd $SRC
#/usr/local/src/opencast-uct/modules/matterhorn-admin-ui-ng# rm -rf node_modules/*
mvn -T 1C clean install -Dmaven.test.skip=true --log-file $log_file
EXEC_STATUS=$?
cd $YML
now=$(date +'%Y-%m-%d %H:%M:%S')
echo " $now : Completed"
echo
if [ $EXEC_STATUS -eq 0 ]; then
compiled=1
echo " SUCCESS"
echo "Last Build ($now) - SUCCESS" > $BUILD_STATUS_FILE
else
compiled=0
echo " ERROR"
echo "Last Build ($now) - ERROR" > $BUILD_STATUS_FILE
fi
echo " (Log: $log_file)"
echo
else
echo " SUCCESS (NOT LIVE)"
fi
else
if [[ ! $valid_src == true ]]; then
echo " NOT BUILD: source ($SRC) contains uncommited/added items."
echo
fi
fi
cd $YML
fi
if $CLEAN && [ $compiled -eq 1 ]; then
echo "Clean: ($HOSTS_FILE)"
if [ $DEPLOY_TYPE = "dev" ]; then
cd $YML
extra="full_clean=true"
if $( ! $DEPLOY); then
# we will start after deploy
extra="$extra start_service=false"
fi
$LIVE && ansible-playbook -i $HOSTS_FILE ansible-clean.yml --extra-vars "$extra"
echo
cd $YML
else
echo " Cleaning can only be performed on 'dev'."
echo
fi
fi
# For Jira comment date
st=$(date +'%Y-%m-%d %H-%M-%S')
extra_vars="production=$([ $DEPLOY_TYPE = "prod" ] && echo "true" || echo "false") deploy_date_time=\"$st\" by=\"$(getCurrentUser)\" "
# the script folder is valid or we are just doing dev OR forced to deploy or rollback
if [[ $FORCE_DEPLOY == true || $ROLLBACK == true || $valid_script == true || $DEPLOY_TYPE == "dev" ]]; then
if [[ $DEPLOY == true || $RECONFIGURE == true || $ROLLBACK == true ]]; then
cd $YML
# copy workflow scripts to default
mkdir -p $FILES/config/default/wfexec/
cp -pr $FILES/worker/wfexec/* $FILES/config/default/wfexec/
echo " Packaging configurations:"
printf " "
for name in "${ACTIVE_SERVER_LIST[@]}"; do
if [ "$CONFIG_DIR" != "$name" ]; then
packageConfiguration $name &
fi
done
wait
echo
echo " Done."
echo
fi
if $DEPLOY && [ $compiled -eq 1 ]; then
cd $YML
echo "Deploy: ($HOSTS_FILE)"
$LIVE && ansible-playbook -i $HOSTS_FILE ansible-deploy.yml --extra-vars "$extra_vars gitbranch=\"$branch\" gitlog=\"$gitlog\" "
$LIVE && echo $(addDeploymentMarker $production "Deploy" $gitlog $branch)
fi
# don't deploy and reconfigure
if $RECONFIGURE && [ $compiled -eq 1 ]; then
cd $YML
echo "Reconfigure: ($HOSTS_FILE)"
$LIVE && ansible-playbook -i $HOSTS_FILE ansible-reconfig.yml --extra-vars "$extra_vars gitbranch=\"$branch\" gitlog=\"$gitlog\" "
$LIVE && echo $(addDeploymentMarker $production "Reconfigure" $gitlog $branch)
fi
if $ROLLBACK; then
cd $YML
echo "Rollback: ($HOSTS_FILE)"
$LIVE && ansible-playbook -i $HOSTS_FILE ansible-rollback.yml --extra-vars "$extra_vars gitbranch=\"$branch\" gitlog=\"$gitlog\" "
$LIVE && echo $(addDeploymentMarker $production "Rollback" $gitlog $branch)
fi
echo
else
printf " NOT "
$DEPLOY && printf "DEPLOYING"
$ROLLBACK && printf "ROLLING BACK"
$RECONFIGURE && printf "RECONFIGURING"
echo ": script ($YML) contains uncommited/added items."
echo
fi
if $LTI; then
#hope that TMP_DIR != '/'
rm -rf $TMP_DIR/*
echo "Creating tarball for LTI"
current_date=`date +%Y%m%d-%H%M%P`
cd $TMP_DIR
cp $SRC/modules/lti/src/main/resources/tools/* . -R
#Versioning of static assets (e.g. css, js)
find . -type f -print0 | xargs -0 sed -i -e "s/%version%/$current_date/g"
tar -zcf ../lti.tar.gz .
rm -rf $TMP_DIR/*
cd $YML
$LIVE && ansible-playbook -i $HOSTS_FILE ansible-lti.yml --extra-vars "$extra_vars gitbranch=\"$branch\" gitlog=\"$gitlog\" "
$LIVE && echo $(addDeploymentMarker $production "LTI" $gitlog $branch)
fi
# STATUS will show list of servers
if $LIST && $( ! $STATUS) && [ $compiled -eq 1 ]; then
showServers
fi
if $VERSION; then
cd $YML
# clean out tmp directory
rm -rf $TMP_DIR/*
echo " Creating dependency check configurations:"
printf " "
for name in "${ACTIVE_SERVER_LIST[@]}"; do
if [ "$CONFIG_DIR" != "$name" ]; then
file=$TMP_DIR/conf-$name.cfg
cp $FILES/check.template $file
packageConfigurationFile $name $file true &
fi
done
wait
echo
echo " Done."
echo
cd $YML
ansible-playbook -i $HOSTS_FILE ansible-check.yml
# clean out tmp directory
rm -rf $TMP_DIR/*
fi
if $STOP; then
cd $YML
$LIVE && ansible-playbook -i $HOSTS_FILE ansible-stop_service.yml
fi
if $STARTUP && [ $compiled -eq 1 ]; then
cd $YML
$LIVE && ansible-playbook -i $HOSTS_FILE ansible-start_service.yml
fi
if $ALIAS; then
cd $YML
$LIVE && ansible-playbook -i $HOSTS_FILE ansible-alias.yml
fi
if $TEST; then
cd $YML
echo "Deploy Testing Script: ($HOSTS_FILE)"
$LIVE && ansible-playbook -i $HOSTS_FILE ansible-testing.yml --extra-vars "$extra_vars gitbranch=\"$branch\" gitlog=\"$gitlog\" "
fi
if $TRACK4K; then
track_log=$(git -C $TRACK4K_SRC show --oneline | head -n 1)
track_branch=$(git -C $TRACK4K_SRC rev-parse --symbolic-full-name --abbrev-ref HEAD)
cd $YML
echo "Deploy Track4K: ($HOSTS_FILE)"
$LIVE && ansible-playbook -i $HOSTS_FILE ansible-track4k.yml --extra-vars "$extra_vars gitbranch=\"$track_branch\" gitlog=\"$track_log\" "
$LIVE && echo $(addDeploymentMarker $production "Track4K" $track_log $track_branch)
fi
if $EMPTYVENUE; then
empty_log=$(git -C $EMPTY_VENUE_SRC show --oneline | head -n 1)
empty_branch=$(git -C $EMPTY_VENUE_SRC rev-parse --symbolic-full-name --abbrev-ref HEAD)
cd $YML
echo "Deploy Empty Venue: ($HOSTS_FILE)"
$LIVE && ansible-playbook -i $HOSTS_FILE ansible-emptyvenuedetector.yml --extra-vars "$extra_vars gitbranch=\"$empty_branch\" gitlog=\"$empty_log\" "
$LIVE && echo $(addDeploymentMarker $production "EmptyVenueDetect" $empty_log $empty_branch)
fi
if $TRIMPOINT; then
trim_log=$(git -C $AUDIO_TRIM_SRC show --oneline | head -n 1)
trim_branch=$(git -C $AUDIO_TRIM_SRC rev-parse --symbolic-full-name --abbrev-ref HEAD)
cd $YML
echo "Deploy Audio Trim Point Detector: ($HOSTS_FILE)"
$LIVE && ansible-playbook -i $HOSTS_FILE ansible-trimpointdetector.yml --extra-vars "$extra_vars gitbranch=\"$trim_branch\" gitlog=\"$trim_log\" "
$LIVE && echo $(addDeploymentMarker $production "AudioTrimPoint" $trim_log $trim_branch)
fi
if $OCR; then
cd $YML
echo "Deploy OCR: ($HOSTS_FILE)"
$LIVE && ansible-playbook -i $HOSTS_FILE ansible-deploy-ocr.yml --extra-vars "$extra_vars gitbranch=\"$branch\" gitlog=\"$gitlog\" "
$LIVE && echo $(addDeploymentMarker $production "OCR" $gitlog $branch)
fi
if $SOX; then
cd $YML
echo "Deploy Sox: ($HOSTS_FILE)"
$LIVE && ansible-playbook -i $HOSTS_FILE ansible-deploy-sox.yml --extra-vars "$extra_vars gitbranch=\"$branch\" gitlog=\"$gitlog\" "
$LIVE && echo $(addDeploymentMarker $production "Sox" $gitlog $branch)
fi
if $STATUS; then
cd $YML
setStatus
echo "Current Status:"
if [ -f $STATUS_FILE ]; then
while read -r line
do
printf "\t$line\n"
done < $STATUS_FILE
fi
if [ -f $BUILD_STATUS_FILE ]; then
while read -r line
do
printf "\t$line\n"
done < $BUILD_STATUS_FILE
echo
fi
if [ $compiled -eq 1 ]; then
showServers
fi
# also display state / running of service
fi
end_time=`date +%s`
duration=$(( $(date "+%s") - $(echo $start_time) ))
printf "Execution time was "
displayTime $duration
echo
cd $CURRENT_DIR
}
usage() {
if [ $# -ne 0 ]; then
echo
echo "One or more options cannot be processed: '$@' (See below)."
echo
fi
echo "Usage: $PROGNAME [options] (Deploy type: dev, production | prod, staging)"
echo
echo " Example: $PROGNAME -bd prod"
echo " Build source, package and deploy to production servers."
echo
echo " NOTE: If configured some options also add JIRA comments and New Relic deployment markers."
echo
echo "Options:"
echo
echo " -h, --help"
echo " This help text."
echo
echo " -a, --all"
echo " Update the source, build it, clean the servers and deploy new build."
echo
echo " --alias"
echo " Deploy the Opencast bash aliases file to each server to make interaction with the sytem easier."
echo
echo " -b, --build"
echo " Will build the assemblies for $SRC (e.g mvn -T 1C clean install) with the current source."
echo
echo " -c, --clean"
echo " Will clean the deployment of opencast on all the associated servers."
echo " a) Clean Database (Only works for development)"
echo " b) Clean Indexes, Distribution and Workspace"
echo
echo " -d, --deploy"
echo " Deploy the currently build assemblies to their respective servers - only if source code is 'clean' or 'dev'."
echo
echo " -f, --force"
echo " Force deploy the currently build assemblies to their respective servers."
echo
echo " -t, --lti-deploy"
echo " Deploy LTI tool static files to the appropriate servers."
echo
echo " -l, --list"
echo " List the servers that can be updated with this script."
echo
echo " --ocr"
echo " Deploy Tesseract and hunspell with all the required language and dictionary files."
echo
echo " --sox"
echo " Deploy Sox."
echo
echo " --test"
echo " Deploy Opencast dependency testing script and run it."
echo
echo " --track4k"
echo " Deploy Track4k binary files to the appropriate nodes."
echo
echo " --audiotrim"
echo " Deploy or update the audio trim detector script from github."
echo
echo " --emptyvenue"
echo " Deploy or update the empty venue detector script from github."
echo
echo " -r, --reconfig"
echo " Reconfigure the respective servers. Deploy configuration build to each,"
echo " which includes custom.properties, encoding profiles and workflows."
echo
echo " --rollback"
echo " Rollback the respective servers. The previous version (backup folder)"
echo " will now be used as the live version and now the live bversion is in the backup folder"
echo
echo " -s, --status"
echo " Display the current git status of the source folder ($SRC) and assemblies."
echo
echo " -u, --update-git"
echo " Will update $SRC to include the latest changes on the selected branch."
echo " e.g git fetch && git pull"
echo
echo " -v, --version"
echo " Run a script on each server and return the version of all the program dependencies."
echo
echo " -x, --xtop"
echo " Stop all opencast services on the respective servers."
echo
echo " -z, --ztart"
echo " Start all opencast services on the respective servers."
echo
echo " --"
echo " Do not interpret any more arguments as options."
echo
}
## Start parsing arguments ##
## TODO: Add optional parameters to
## - build: 0 (default) Do All, 1 build src, 2 build cfg
# - clean: 0 (default) Do All, 1 clean only db, 2 clean shared+archive+distribution
ARGS=$(getopt -o ":abcdhlrstuvxz" -l ":one,all,build,clean,deploy,help,list,reconfig,rollback,update-git,status,version,xtop,ztart,lti-deploy,alias,test,track4k,audiotrim,emptyvenue,ocr,sox" -n "$PROGNAME" -- "$@")
if [ $? -ne 0 ] || [ $# -eq 0 ]; then
# if error in parsing args display usage
usage $@
exit 1
fi
MORE=true
eval set -- "$ARGS"
while true; do
case "$1" in
-h|--help)
usage
exit 0
;;
-a|--all)
BUILD=true
CLEAN=true
DEPLOY=true
UPDATE=true
STATUS=true
ACTIONS=5
MORE=false
shift
;;
--alias)
$MORE && ALIAS=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
-b|--build)
$MORE && BUILD=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
-c|--clean)
$MORE && CLEAN=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
-d|--deploy)
$MORE && DEPLOY=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
-f|--force)
$MORE && FORCE_DEPLOY=true
$MORE && DEPLOY=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
-t|--lti-deploy)
$MORE && LTI=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
--test)
$MORE && TEST=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
--track4k)
$MORE && TRACK4K=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
--audiotrim)
$MORE && TRIMPOINT=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
--emptyvenue)
$MORE && EMPTYVENUE=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
-l|--list)
$MORE && LIST=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
--ocr)
$MORE && OCR=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
--sox)
$MORE && SOX=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
-u|--update-git)
$MORE && UPDATE=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
-r|--reconfig)
$MORE && RECONFIGURE=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
--rollback)
$MORE && ROLLBACK=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
-s|--status)
$MORE && STATUS=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
-v|--version)
$MORE && VERSION=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
-x|--xtop)
$MORE && STOP=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
-z|--ztart)
$MORE && STARTUP=true
$MORE && ACTIONS=$((ACTIONS+1))
shift
;;
--)
shift
break
;;
-*)
echo "Invalid option '$1'. Use --help to see the valid options" >&2
exit 1
;;
# an option argument, continue
*) ;;
esac
done
string="$@"
for arg in "${string,}"
do
case "$arg" in
"dev" )
DEPLOY_TYPE="dev"
HOSTS_FILE=$HOSTS_FOLDER"dev"
shift
break
;;
"prod"|"production" )
DEPLOY_TYPE="prod"
HOSTS_FILE=$HOSTS_FOLDER"production"
shift
break
;;
"staging" )
DEPLOY_TYPE="staging"
HOSTS_FILE=$HOSTS_FOLDER"staging"
shift
break
;;
* )
args+=($arg)
esac
done
if [ -z "$DEPLOY_TYPE" ]; then
DEPLOY_TYPE="dev"
HOSTS_FILE=$HOSTS_FOLDER"dev"
fi
if [ $ACTIONS -eq 0 ]; then
# if there are no actions / only deploy type then show usage
usage $@
exit 1
fi
# Write out the required files for this build type (deploy-[type].cfg) to the files for:
# - build and package for each server
# - deploy with ansible script
cd $YML
cp $FILES/build-all.template files/config/build-default.cfg
cp $FILES/dbservers.template group_vars/dbservers