-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_local.sh
executable file
·1490 lines (910 loc) · 45 KB
/
run_local.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
#!/usr/bin/env bash
# DO NOT EDIT THIS FILE!
# Generated by fulgens (https://www.npmjs.com/package/fulgens)
# Version: 0.0.24
trap cleanup 2
set -e
#---------------------
# START - FunctionsBuilder
jdk_version() {
# returns the JDK version.
# 8 for 1.8.0_nn, 9 for 9-ea etc, and "no_java" for undetected
# from https://stackoverflow.com/questions/7334754/correct-way-to-check-java-version-from-bash-script
local result
local java_cmd
if [[ -n $(type -p java) ]]
then
java_cmd=java
elif [[ (-n "$JAVA_HOME") && (-x "$JAVA_HOME/bin/java") ]]
then
java_cmd="$JAVA_HOME/bin/java"
fi
local IFS=$'\n'
# remove \r for Cygwin
local lines=$("$java_cmd" -Xms32M -Xmx32M -version 2>&1 | tr '\r' '\n')
if [[ -z $java_cmd ]]
then
result=no_java
else
for line in $lines; do
if [[ (-z $result) && ($line = *"version \""*) ]]
then
local ver=$(echo $line | sed -e 's/.*version "\(.*\)"\(.*\)/\1/; 1q')
# on macOS, sed doesn't support '?'
if [[ $ver = "1."* ]]
then
result=$(echo $ver | sed -e 's/1\.\([0-9]*\)\(.*\)/\1/; 1q')
else
result=$(echo $ver | sed -e 's/\([0-9]*\)\(.*\)/\1/; 1q')
fi
fi
done
fi
echo "$result"
}
# END - FunctionsBuilder
#---------------------
verbosePrint() {
if [ "$VERBOSE" == "YES" ]; then
echo -e "$1"
fi
}
startDockerNetwork() {
if [ -z "$DOCKER_NETWORKED_CHECKED" ]; then
DOCKER_NETWORKED_CHECKED=YES
if ! docker network ls|grep -s "cycnet"; then
verbosePrint "Starting docker network cycnet on 10.176.252.0/24"
docker network create -d bridge --subnet 10.176.252.0/24 --gateway 10.176.252.1 "cycnet"
else
verbosePrint "Docker network cycnet already running"
fi
fi
}
#---------------------
# START - CleanupBuilder
cleanup()
{
echo "****************************************************************"
echo "Stopping software .....please wait...."
echo "****************************************************************"
set +e
ALL_COMPONENTS=(db engine tomcat)
for componentToStop in "${ALL_COMPONENTS[@]}"; do
IFS=',' read -r -a keepRunningArray <<< "$KEEP_RUNNING"
componentFoundToKeepRunning=0
for keepRunningToFindeElement in "${keepRunningArray[@]}"; do
if [ "$componentToStop" == "$keepRunningToFindeElement" ]; then
echo "Not stopping $componentToStop!"
componentFoundToKeepRunning=1
fi
done
if [ "$componentFoundToKeepRunning" -eq 0 ]; then
if [ "$START_DB" = "YES" ]; then
if [ "$componentToStop" == "db" ]; then
echo "Stopping $componentToStop ..."
if [ "$TYPE_SOURCE_DB" == "docker" ]; then
docker rm -f $dockerContainerIDdb
rm -f .dbPid
fi
fi
fi
if [ "$START_ENGINE" = "YES" ]; then
if [ "$componentToStop" == "engine" ]; then
echo "Stopping $componentToStop ..."
if [ "$TYPE_SOURCE_ENGINE" == "local" ]; then
echo exit|nc localhost 9998
rm -f .enginePid
fi
if [ "$TYPE_SOURCE_ENGINE" == "docker" ]; then
docker rm -f $dockerContainerIDengine
rm -f .enginePid
fi
fi
fi
if [ "$START_TOMCAT" = "YES" ]; then
if [ "$componentToStop" == "tomcat" ]; then
echo "Stopping $componentToStop ..."
if [ "$TYPE_SOURCE_TOMCAT" == "docker" ]; then
docker rm -f $dockerContainerIDtomcat
rm -f .tomcatPid
fi
if [ "$TYPE_SOURCE_TOMCAT" == "download" ]; then
./localrun/apache-tomcat-$TOMCAT_VERSION/bin/shutdown.sh
rm -f .tomcatPid
fi
fi
fi
fi
done
exit 0
}
# END - CleanupBuilder
#---------------------
#---------------------
# START - OptionsBuilder
usage="
usage: $(basename "$0") [options] [<component(s)>]
Options:
-h show this help text
-s skip any build
-S skip consistency check against Fulgensfile
-c [all|build] clean local run directory, when a build is scheduled for execution it also does a full build
-k [component] keep comma sperarated list of components running
-t [component:type:[path|version]] run component inside [docker] container, [download] component or [local] use installed component from path
-v enable Verbose
-V start VirtualBox via vagrant, install all dependencies, ssh into the VM and run
-j version macOS only: set/overwrite JAVA_HOME to a specific locally installed version, use format from/for: /usr/libexec/java_home [-V]
-f tail the apache catalina log at the end
Url: http://localhost:8080/cyr
Details for components:
build {Source:\"mvn\", Default-Type:\"local\", Version-Info: \"Tested with 3-jdk-11\"}
-t build:local #build local and respect -j
-t build:docker:[TAG] #docker based build, default tag: latest, uses image https://hub.docker.com/_/maven
db {Source:\"couchdb\", Default-Type:\"docker:2\", Version-Info: \"Tested with 1.7 & 2\"}
-t db:local #reuse a local, running CouchDB installation, does not start/stop this CouchDB
-t db:docker:[TAG] #start docker, default tag 2, uses image https://hub.docker.com/_/couchdb
engine {Source:\"shell\", Default-Type:\"local\", Version-Info: \"Max Java 8\"}
-t engine:local #On macOS: Java version overwritten to 1.8
-t engine:local #start a local shell script
-t engine:docker:[latest] #start inside docker, default tag 8-jre, uses image https://hub.docker.com/_/openjdk
tomcat {Source:\"tomcat\", Default-Type:\"download:9\", Version-Info: \"Tested with 7 & 9\"}
-t tomcat:docker:[TAG] #start docker, default tag tomcat9-openjdk11-openj9, uses image https://hub.docker.com/r/oglimmer/adoptopenjdk-tomcat
-t tomcat:download:[7|8|9] #start fresh downloaded tomcat, default version 9 and respect -j
-t tomcat:local:TOMCAT_HOME_PATH #reuse tomcat installation from TOMCAT_HOME_PATH, does not start/stop this tomcat
"
cd "$(cd "$(dirname "$0")";pwd -P)"
BASE_PWD=$(pwd)
BUILD=local
while getopts ':hsSc:k:x:t:vVj:f' option; do
case "$option" in
h) echo "$usage"
exit;;
s) SKIP_BUILD=YES;;
S) SKIP_HASH_CHECK=YES;;
c)
CLEAN=$OPTARG
if [ "$CLEAN" != "all" -a "$CLEAN" != "build" ]; then
echo "Illegal -c parameter" && exit 1
fi
;;
k) KEEP_RUNNING=$OPTARG;;
x) SKIP_STARTING=$OPTARG;;
t) TYPE_SOURCE=$OPTARG;;
v) VERBOSE=YES;;
V) VAGRANT=YES;;
j) JAVA_VERSION=$OPTARG;;
f) TAIL=YES;;
:) printf "missing argument for -%s\\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1;;
\\?) printf "illegal option: -%s\\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1;;
esac
done
shift $((OPTIND - 1))
if [ -z "$1" ]; then
declare START_BUILD=YES
declare START_DB=YES
declare START_ENGINE=YES
declare START_TOMCAT=YES
else
ALL_COMPONENTS=(BUILD DB ENGINE TOMCAT)
for comp in "$@"; do
compUpper=$(echo $comp | awk '{print toupper($0)}')
compValid=0
for compDefined in "${ALL_COMPONENTS[@]}"; do
if [ "$compDefined" = "$compUpper" ]; then
compValid=1
fi
done
if [ "$compValid" -eq 0 ]; then
echo "Component $comp is invalid!"
exit 1
fi
declare START_$compUpper=YES
done
fi
# END - OptionsBuilder
#---------------------
if [ "$SKIP_HASH_CHECK" != "YES" ]; then
if which md5 1>/dev/null; then
declare SELF_HASH_MD5="15626217ec4bb58e4d3148ff305d73c0"
declare SOURCE_FILES=(Fulgensfile Fulgensfile.js)
for SOURCE_FILE in ${SOURCE_FILES[@]}; do
declare SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")">/dev/null&&pwd)"
if [ -f "$SCRIPT_DIR/$SOURCE_FILE" ]; then
if [ "$SELF_HASH_MD5" != "$(md5 -q $SCRIPT_DIR/$SOURCE_FILE)" ]; then
echo "$SOURCE_FILE doesn not match!"
exit 1
fi
fi
done
fi
fi
#---------------------
# START - DependencycheckBuilder
mvn --version 1>/dev/null || exit 1;
docker --version 1>/dev/null || exit 1;
java -version 2>/dev/null || exit 1;
curl --version 1>/dev/null || exit 1;
# END - DependencycheckBuilder
#---------------------
# clean if requested
if [ -n "$CLEAN" ]; then
if [ "$CLEAN" == "all" ]; then
if [ "$VERBOSE" == "YES" ]; then echo "rm -rf localrun"; fi
rm -rf localrun
fi
fi
#---------------------
# START - GlobalVariablesBuilder
verbosePrint "DEFAULT: TYPE_SOURCE_BUILD=local"
TYPE_SOURCE_BUILD=local
verbosePrint "DEFAULT: TYPE_SOURCE_DB=docker"
TYPE_SOURCE_DB=docker
verbosePrint "DEFAULT: TYPE_SOURCE_ENGINE=local"
TYPE_SOURCE_ENGINE=local
verbosePrint "DEFAULT: TYPE_SOURCE_TOMCAT=download"
TYPE_SOURCE_TOMCAT=download
# END - GlobalVariablesBuilder
#---------------------
if [ "$(uname)" = "Linux" ]; then
ADD_HOST_INTERNAL="--add-host host.docker.internal:$(ip -4 addr show scope global dev docker0 | grep inet | awk '{print $2}' | cut -d / -f 1)"
fi
mkdir -p localrun
f_deploy() {
echo "No plugin defined f_deploy()"
}
#---------------------
# START - PrepareBuilder
if [ "$(uname)" == "Darwin" ]; then
if [ -n "$JAVA_VERSION" ]; then
export JAVA_HOME=$(/usr/libexec/java_home -v $JAVA_VERSION)
fi
fi
if [ "$VAGRANT" == "YES" -a "$VAGRANT_IGNORE" != "YES" ]; then
mkdir -p localrun
cd localrun
cat <<-EOF > Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.synced_folder "../", "/share_host"
config.vm.provider "virtualbox" do |vb|
vb.memory = "1536"
vb.cpus = 4
end
config.vm.provision "shell", inline: <<-SHELL
apt-get update
if [ "\$(cat /etc/*release|grep ^ID=)" = "ID=debian" ]; then \\
if [ "\$(cat /etc/debian_version)" = "8.11" ]; then \\
apt-get -qy install maven openjdk-8-jdk-headless couchdb docker.io; \\
elif [ "\$(cat /etc/debian_version)" = "9.5" ]; then \\
apt-get -qy install maven openjdk-8-jdk-headless couchdb docker.io; \\
else apt-get -qy install maven openjdk-8-jdk-headless couchdb docker.io; fi \\
elif [ "\$(cat /etc/*release|grep ^ID=)" = "ID=ubuntu" ]; then \\
apt-get -qy install maven openjdk-8-jdk-headless couchdb docker.io; \\
else \\
echo "only debian or ubuntu are supported."; \\
exit 1; \\
fi \\
echo "Now continue with..."
echo "\$ cd /share_host"
echo "\$ sudo ./run_local.sh -f"
echo "...then browse to http://localhost:8080/cyr"
SHELL
end
EOF
vagrant up
if [ -f "../run_local.sh" ]; then
vagrant ssh -c "cd /share_host && sudo ./run_local.sh -f"
else
echo "Save the fulgens output into a bash script (e.g. run_local.sh) and use it inside the new VM"
fi
exit 1
fi
# END - PrepareBuilder
#---------------------
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# MvnPlugin // build
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
verbosePrint "MvnPlugin // build"
if [ "$START_BUILD" = "YES" ]; then
#---------------------
# START - Plugin-PrepareComp
IFS=',' read -r -a array <<< "$TYPE_SOURCE"
for typeSourceElement in "${array[@]}"; do
IFS=: read comp type pathOrVersion <<< "$typeSourceElement"
if [ "$comp" == "build" ]; then
TYPE_SOURCE_BUILD=$type
if [ "$TYPE_SOURCE_BUILD" == "local" ]; then
TYPE_SOURCE_BUILD_PATH=$pathOrVersion
else
TYPE_SOURCE_BUILD_VERSION=$pathOrVersion
fi
fi
done
if [ "$TYPE_SOURCE_BUILD" == "docker" ]; then
if [ -z "$TYPE_SOURCE_BUILD_VERSION" ]; then
TYPE_SOURCE_BUILD_VERSION=latest
fi
fi
verbosePrint "TYPE_SOURCE_BUILD = $TYPE_SOURCE_BUILD // TYPE_SOURCE_BUILD_PATH = $TYPE_SOURCE_BUILD_PATH // TYPE_SOURCE_BUILD_VERSION = $TYPE_SOURCE_BUILD_VERSION"
# END - Plugin-PrepareComp
#---------------------
if [ "$TYPE_SOURCE_BUILD" == "local" ]; then
f_build() {
verbosePrint "pwd=$(pwd)\nmvn $MVN_CLEAN $MVN_OPTS package"
mvn $MVN_CLEAN $MVN_OPTS package
}
fi
if [ "$TYPE_SOURCE_BUILD" == "docker" ]; then
dockerImage=maven
f_build() {
verbosePrint "pwd=$(pwd)\ndocker run --name=build --rm -v $(pwd):/usr/src/build -v "$(pwd)/localrun/.m2":/root/.m2 -w /usr/src/build $dockerImage:$TYPE_SOURCE_BUILD_VERSION mvn $MVN_CLEAN $MVN_OPTS package"
docker run --name=build --rm -v "$(pwd)":/usr/src/build -v "$(pwd)/localrun/.m2":/root/.m2 -w /usr/src/build $dockerImage:$TYPE_SOURCE_BUILD_VERSION mvn $MVN_CLEAN $MVN_OPTS package
}
fi
if [ "$SKIP_BUILD" != "YES" ]; then
if [ -n "$CLEAN" ]; then
MVN_CLEAN=clean
fi
f_build
else
verbosePrint "Mvn build skipped."
fi
fi
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# CouchdbPlugin // db
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
verbosePrint "CouchdbPlugin // db"
if [ "$START_DB" = "YES" ]; then
#---------------------
# START - Plugin-PrepareComp
IFS=',' read -r -a array <<< "$TYPE_SOURCE"
for typeSourceElement in "${array[@]}"; do
IFS=: read comp type pathOrVersion <<< "$typeSourceElement"
if [ "$comp" == "db" ]; then
TYPE_SOURCE_DB=$type
if [ "$TYPE_SOURCE_DB" == "local" ]; then
TYPE_SOURCE_DB_PATH=$pathOrVersion
else
TYPE_SOURCE_DB_VERSION=$pathOrVersion
fi
fi
done
if [ "$TYPE_SOURCE_DB" == "docker" ]; then
if [ -z "$TYPE_SOURCE_DB_VERSION" ]; then
TYPE_SOURCE_DB_VERSION=2
fi
fi
verbosePrint "TYPE_SOURCE_DB = $TYPE_SOURCE_DB // TYPE_SOURCE_DB_PATH = $TYPE_SOURCE_DB_PATH // TYPE_SOURCE_DB_VERSION = $TYPE_SOURCE_DB_VERSION"
# END - Plugin-PrepareComp
#---------------------
if [ "$TYPE_SOURCE_DB" == "docker" ]; then
if [ ! -f ".dbPid" ]; then
startDockerNetwork
verbosePrint "docker run --rm -d -p 5984:5984 -m 200M --net=cycnet --name=db $ADD_HOST_INTERNAL couchdb:$TYPE_SOURCE_DB_VERSION"
dockerContainerIDdb=$(docker run --rm -d -p 5984:5984 \
-m 200M \
--net=cycnet --name=db $ADD_HOST_INTERNAL \
couchdb:$TYPE_SOURCE_DB_VERSION)
echo "$dockerContainerIDdb">.dbPid
else
dockerContainerIDdb=$(<.dbPid)
echo "Reusing already running instance $dockerContainerIDdb"
fi
fi
if [ "$TYPE_SOURCE_DB" == "local" ]; then
if [ -f ".dbPid" ]; then
echo "couchdb db running but started from different source type"
exit 1
fi
fi
while [ "$(curl --write-out %{http_code} --silent --output /dev/null http://localhost:5984)" != "200" ]; do
echo "waiting for couchdb..."
sleep 1
done
if [[ "$(curl -s http://localhost:5984/cyc)" =~ .*"error".*"not_found".* ]]; then
curl -X PUT http://localhost:5984/cyc
curl -X POST -H "Content-Type: application/json" -d @persistence/src/couchdb/_design-GameRun-curl.json http://localhost:5984/cyc
curl -X POST -H "Content-Type: application/json" -d @persistence/src/couchdb/_design-GameWinners-curl.json http://localhost:5984/cyc
curl -X POST -H "Content-Type: application/json" -d @persistence/src/couchdb/_design-User-curl.json http://localhost:5984/cyc
fi
fi
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ShellPlugin // engine
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
verbosePrint "ShellPlugin // engine"
if [ "$START_ENGINE" = "YES" ]; then
#---------------------
# START - Plugin-PrepareComp
IFS=',' read -r -a array <<< "$TYPE_SOURCE"
for typeSourceElement in "${array[@]}"; do
IFS=: read comp type pathOrVersion <<< "$typeSourceElement"
if [ "$comp" == "engine" ]; then
TYPE_SOURCE_ENGINE=$type
if [ "$TYPE_SOURCE_ENGINE" == "local" ]; then
TYPE_SOURCE_ENGINE_PATH=$pathOrVersion
else
TYPE_SOURCE_ENGINE_VERSION=$pathOrVersion
fi
fi
done
if [ "$TYPE_SOURCE_ENGINE" == "docker" ]; then
if [ -z "$TYPE_SOURCE_ENGINE_VERSION" ]; then
TYPE_SOURCE_ENGINE_VERSION=8-jre
fi
fi
verbosePrint "TYPE_SOURCE_ENGINE = $TYPE_SOURCE_ENGINE // TYPE_SOURCE_ENGINE_PATH = $TYPE_SOURCE_ENGINE_PATH // TYPE_SOURCE_ENGINE_VERSION = $TYPE_SOURCE_ENGINE_VERSION"
# END - Plugin-PrepareComp
#---------------------
#---------------------
# START - Plugin-PreStart
CYC_ENG_CON_PATH=localrun/cyc-engine-container
mkdir -p $CYC_ENG_CON_PATH
cp engine-container/target/engine-container-jar-with-dependencies.jar $CYC_ENG_CON_PATH
mkdir -p $CYC_ENG_CON_PATH/logs
cp ansible/roles/cyc-container/files/scripts/security.policy $CYC_ENG_CON_PATH
cp ansible/roles/cyc-container/files/scripts/run.sh $CYC_ENG_CON_PATH
chmod 777 $CYC_ENG_CON_PATH/run.sh
mkdir -p $CYC_ENG_CON_PATH/cyc001
cp engine/target/engine-jar-with-dependencies.jar $CYC_ENG_CON_PATH/cyc001
if [ "$(uname)" = "Darwin" ]; then
ORIGINAL_JAVA_HOME="$JAVA_HOME"
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
elif [ "$(jdk_version)" != "8" ]; then
echo "ERROR: the local Java version is different to the one defined in Fulgensfile.version for this component!"
exit 1
fi
# END - Plugin-PreStart
#---------------------
if [ "$TYPE_SOURCE_ENGINE" == "local" ]; then
if [ ! -f ".enginePid" ]; then
verbosePrint "nohup localrun/cyc-engine-container/run.sh 1>>localrun/engine.log 2>>localrun/engine.log &"
export CYC_ENGINE_CONTAINER="localrun/cyc-engine-container"; export OPTS="-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Dcyc.properties=/tmp/b6216549/cyc_engine.properties"
nohup "localrun/cyc-engine-container/run.sh" 1>>"localrun/engine.log" 2>>"localrun/engine.log" &
shellPIDengine=$!
echo "$shellPIDengine">".enginePid"
else
shellPIDengine=$(<".enginePid")
echo "Reusing already running instance $shellPIDengine"
fi
fi
if [ "$TYPE_SOURCE_ENGINE" == "docker" ]; then
#if [ -f "$BASE_PWD/.enginePid" ] && [ "$(<"$BASE_PWD/.enginePid")" == "download" ]; then
# echo "node running but started from different source type"
# exit 1
#fi
if [ ! -f "$BASE_PWD/.enginePid" ]; then
startDockerNetwork
if [ "$TYPE_SOURCE_DB" == "docker" ]; then
REPLVAR_ENGINE_DB="db"
elif [ "$TYPE_SOURCE_DB" == "local" ]; then
REPLVAR_ENGINE_DB="host.docker.internal"
fi
mkdir -p localrun/b6216549
cat <<EOTb6216549 > localrun/b6216549/cyc_engine.properties
bind=0.0.0.0
couchdb.host=$REPLVAR_ENGINE_DB
EOTb6216549
mkdir -p localrun/d8a6791d
cat <<EOTd8a6791d > localrun/d8a6791d/security.policy
grant codeBase "file:/var/lib/tomcat7/jmxtrans/jmxtrans-agent.jar" {
permission javax.management.MBeanPermission "-#-[-]", "queryNames";
permission javax.management.MBeanPermission "sun.management.ClassLoadingImpl#-[java.lang:type=ClassLoading]", "queryNames";
permission javax.management.MBeanPermission "sun.management.ClassLoadingImpl#LoadedClassCount[java.lang:type=ClassLoading]", "getAttribute";
permission javax.management.MBeanPermission "sun.management.ThreadImpl#-[java.lang:type=Threading]", "queryNames";
permission javax.management.MBeanPermission "sun.management.ThreadImpl#ThreadCount[java.lang:type=Threading]", "getAttribute";
permission javax.management.MBeanPermission "sun.management.MemoryImpl#-[java.lang:type=Memory]", "queryNames";
permission javax.management.MBeanPermission "sun.management.MemoryImpl#NonHeapMemoryUsage[java.lang:type=Memory]", "getAttribute";
permission javax.management.MBeanPermission "sun.management.MemoryImpl#HeapMemoryUsage[java.lang:type=Memory]", "getAttribute";
permission javax.management.MBeanPermission "sun.management.GarbageCollectorImpl#-[java.lang:name=*,type=GarbageCollector]", "queryNames";
permission javax.management.MBeanPermission "sun.management.GarbageCollectorImpl#CollectionTime[java.lang:name=*,type=GarbageCollector]", "getAttribute";
permission javax.management.MBeanPermission "sun.management.GarbageCollectorImpl#CollectionCount[java.lang:name=*,type=GarbageCollector]", "getAttribute";
// OS X
permission javax.management.MBeanPermission "sun.management.OperatingSystemImpl#-[java.lang:type=OperatingSystem]", "queryNames";
permission javax.management.MBeanPermission "sun.management.OperatingSystemImpl#SystemLoadAverage[java.lang:type=OperatingSystem]", "getAttribute";
permission javax.management.MBeanPermission "sun.management.OperatingSystemImpl#SystemCpuLoad[java.lang:type=OperatingSystem]", "getAttribute";
permission javax.management.MBeanPermission "sun.management.OperatingSystemImpl#ProcessCpuLoad[java.lang:type=OperatingSystem]", "getAttribute";
permission javax.management.MBeanPermission "sun.management.OperatingSystemImpl#OpenFileDescriptorCount[java.lang:type=OperatingSystem]", "getAttribute";
permission javax.management.MBeanPermission "sun.management.OperatingSystemImpl#FreeSwapSpaceSize[java.lang:type=OperatingSystem]", "getAttribute";
permission javax.management.MBeanPermission "sun.management.OperatingSystemImpl#FreePhysicalMemorySize[java.lang:type=OperatingSystem]", "getAttribute";
permission javax.management.MBeanPermission "sun.management.OperatingSystemImpl#CommittedVirtualMemorySize[java.lang:type=OperatingSystem]", "getAttribute";
// Linux
permission javax.management.MBeanPermission "com.sun.management.UnixOperatingSystem#-[java.lang:type=OperatingSystem]", "queryNames";
permission javax.management.MBeanPermission "com.sun.management.UnixOperatingSystem#SystemLoadAverage[java.lang:type=OperatingSystem]", "getAttribute";
permission javax.management.MBeanPermission "com.sun.management.UnixOperatingSystem#SystemCpuLoad[java.lang:type=OperatingSystem]", "getAttribute";
permission javax.management.MBeanPermission "com.sun.management.UnixOperatingSystem#ProcessCpuLoad[java.lang:type=OperatingSystem]", "getAttribute";
permission javax.management.MBeanPermission "com.sun.management.UnixOperatingSystem#OpenFileDescriptorCount[java.lang:type=OperatingSystem]", "getAttribute";
permission javax.management.MBeanPermission "com.sun.management.UnixOperatingSystem#FreeSwapSpaceSize[java.lang:type=OperatingSystem]", "getAttribute";
permission javax.management.MBeanPermission "com.sun.management.UnixOperatingSystem#FreePhysicalMemorySize[java.lang:type=OperatingSystem]", "getAttribute";
permission javax.management.MBeanPermission "com.sun.management.UnixOperatingSystem#CommittedVirtualMemorySize[java.lang:type=OperatingSystem]", "getAttribute";
permission javax.management.MBeanPermission "de.oglimmer.cyc.mbean.GameRunStats#-[de.oglimmer.cyc:type=GameRunStats]", "queryNames";
permission javax.management.MBeanPermission "de.oglimmer.cyc.mbean.GameRunStats#*[de.oglimmer.cyc:type=GameRunStats]", "getAttribute";
permission java.net.SocketPermission "vpn.oglimmer.de", "resolve";
permission java.net.SocketPermission "104.236.33.19:2003", "connect,resolve";
};
grant codeBase "file:\${cyc.home}/engine-container-jar-with-dependencies.jar" {
permission java.lang.RuntimePermission "accessClassInPackage.com.sun.proxy";
permission java.lang.RuntimePermission "accessClassInPackage.sun.reflect";
// needed for netty
permission java.util.PropertyPermission "io.netty.eventLoopThreads", "read";
permission java.util.PropertyPermission "io.netty.noUnsafe", "read";
permission java.util.PropertyPermission "io.netty.tryUnsafe", "read";
permission java.util.PropertyPermission "io.netty.noJavassist", "read";
permission java.util.PropertyPermission "io.netty.noKeySetOptimization", "read";
permission java.util.PropertyPermission "io.netty.selectorAutoRebuildThreshold", "read";
permission java.util.PropertyPermission "io.netty.initialSeedUniquifier", "read";
permission java.util.PropertyPermission "io.netty.noPreferDirect", "read";
permission java.util.PropertyPermission "io.netty.noResourceLeakDetection", "read";
permission java.util.PropertyPermission "org.jboss.netty.tryUnsafe", "read";
permission java.util.PropertyPermission "sun.nio.ch.bugLevel", "read,write";
permission java.util.PropertyPermission "cyc.debug", "read";
permission java.util.PropertyPermission "cyc.home", "read";
permission java.io.FilePermission "/usr/bin/id", "execute";
permission java.io.FilePermission "/proc/sys/net/core/somaxconn", "read";
permission java.lang.RuntimePermission "setIO";
permission java.lang.RuntimePermission "accessClassInPackage.sun.misc";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
permission java.net.NetPermission "getNetworkInformation";
permission java.lang.management.ManagementPermission "monitor";
permission java.net.SocketPermission "127.0.0.1:-", "accept,resolve";
permission java.net.SocketPermission "localhost", "resolve,listen";
permission java.lang.RuntimePermission "accessClassInPackage.sun.reflect";
permission java.lang.RuntimePermission "accessClassInPackage.sun.text.resources";
permission java.lang.RuntimePermission "accessClassInPackage.sun.util.resources";
permission java.lang.RuntimePermission "readFileDescriptor";
permission java.lang.RuntimePermission "writeFileDescriptor";
permission java.lang.RuntimePermission "accessClassInPackage.sun.net.www.protocol.jar";
permission java.net.NetPermission "getProxySelector";
permission java.security.SecurityPermission "getPolicy";
permission java.security.SecurityPermission "getProperty.networkaddress.cache.negative.ttl";
permission java.security.SecurityPermission "getProperty.networkaddress.cache.ttl";
permission java.util.logging.LoggingPermission "control";
permission java.util.PropertyPermission "org.xeustechnologies.jcl.AbstractClassLoader\$SystemLoader", "read";
permission java.util.PropertyPermission "org.xeustechnologies.jcl.AbstractClassLoader\$ParentLoader", "read";
permission java.util.PropertyPermission "org.xeustechnologies.jcl.AbstractClassLoader\$CurrentLoader", "read";
permission java.util.PropertyPermission "org.xeustechnologies.jcl.AbstractClassLoader\$ThreadContextLoader", "read";
permission java.util.PropertyPermission "org.xeustechnologies.jcl.JarClassLoader\$LocalLoader", "read";
permission java.util.PropertyPermission "jcl.suppressCollisionException", "read";
permission java.util.PropertyPermission "jcl.suppressMissingResourceException", "read";
permission java.util.PropertyPermission "osgi.bootdelegation", "read";
permission java.util.PropertyPermission "osgi.bootdelegation.strict", "read";
permission java.util.PropertyPermission "org.osgi.framework.bootdelegation", "read";
permission java.util.PropertyPermission "file.encoding", "read";
permission java.util.PropertyPermission "java.home", "read";
permission java.util.PropertyPermission "java.net.useSystemProxies", "read";
permission java.util.PropertyPermission "java.protocol.handler.pkgs", "read";
permission java.util.PropertyPermission "java.util.Arrays.useLegacyMergeSort", "read";
permission java.util.PropertyPermission "jcl.autoProxy", "read";
permission java.util.PropertyPermission "line.separator", "read";
permission java.util.PropertyPermission "org.apache.commons.logging.diagnostics.dest", "read";
permission java.util.PropertyPermission "org.apache.commons.logging.Log", "read";
permission java.util.PropertyPermission "org.apache.commons.logging.log", "read";
permission java.util.PropertyPermission "org.apache.commons.logging.Log.allowFlawedContext", "read";
permission java.util.PropertyPermission "org.apache.commons.logging.Log.allowFlawedDiscovery", "read";
permission java.util.PropertyPermission "org.apache.commons.logging.Log.allowFlawedHierarchy", "read";
permission java.util.PropertyPermission "org.apache.commons.logging.LogFactory", "read";
permission java.util.PropertyPermission "org.apache.commons.logging.LogFactory.HashtableImpl", "read";
permission java.util.PropertyPermission "socksProxyHost", "read";
permission java.util.PropertyPermission "sun.io.serialization.extendedDebugInfo", "read";
permission java.util.PropertyPermission "sun.net.inetaddr.ttl", "read";
permission java.util.PropertyPermission "sun.net.maxDatagramSockets", "read";
permission java.util.PropertyPermission "sun.reflect.proxy.allowsNewInstance", "read";
permission java.util.PropertyPermission "sun.reflect.proxy.allowsNullLoader", "read";
permission java.util.PropertyPermission "sun.util.logging.disableCallerCheck", "read";
permission java.util.PropertyPermission "user.dir", "read";
};
// Standard extensions get all permissions by default
grant codeBase "file:\${{java.ext.dirs}}/*" {
permission java.security.AllPermission;
};
// MacOS X extensions START
grant codeBase "file:\${user.home}/Library/Java/Extensions/*" {
permission java.security.AllPermission;
};
grant codeBase "file:/Library/Java/Extensions/*" {
permission java.security.AllPermission;
};
grant codeBase "file:/System/Library/Java/Extensions/*" {
permission java.security.AllPermission;
};
grant codeBase "file:/Network/Library/Java/Extensions/*" {
permission java.security.AllPermission;
};
// MacOS X extensions END
// Since JCL (Java ClassLoader doesn't support proper codeBase handling, we have to put permission for the engine here)
// should be: grant codeBase "file:\${cyc.home}/cyc*/-" { // sure "*" isn't supported, but that doesn't matter anyway