-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·479 lines (431 loc) · 15.6 KB
/
setup.sh
File metadata and controls
executable file
·479 lines (431 loc) · 15.6 KB
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
#!/bin/bash
#
# Copyright 2012 - 2016 by TIBCO Software Inc.
# All rights reserved.
#
# This software is confidential and proprietary information of
# TIBCO Software Inc.
#
#
print_Debug()
{
if [[ ${BW_LOGLEVEL} && "${BW_LOGLEVEL,,}"="debug" ]]; then
echo $1
fi
}
extract ()
{
if [ -f $1 ] ; then
case $1 in
*.tar.gz) tar xvfz $1;;
*.gz) gunzip $1;;
*.tar) tar xvf $1;;
*.tgz) tar xvzf $1;;
*.tar.bz2) tar xvjf $1;;
*.bz2) bunzip2 $1;;
*.rar) unrar x $1;;
*.tbz2) tar xvjf $1;;
*.zip) unzip -q $1;;
*.Z) uncompress $1;;
*) echo "can't extract from $1";;
esac
else
echo "no file called $1"
fi
}
checkProfile()
{
BUILD_DIR=/tmp
defaultProfile=default.substvar
manifest=$BUILD_DIR/META-INF/MANIFEST.MF
bwAppConfig="TIBCO-BW-ConfigProfile"
bwAppNameHeader="Bundle-SymbolicName"
bwEdition='bwcf'
#bwceTarget='TIBCO-BWCE-Edition-Target:'
if [ -f ${manifest} ]; then
bwAppProfileStr=`grep -o $bwAppConfig.*.substvar ${manifest}`
bwBundleAppName=`while read line; do printf "%q\n" "$line"; done<${manifest} | awk '/.*:/{printf "%s%s", (NR==1)?"":RS,$0;next}{printf "%s", FS $0}END{print ""}' | grep -o $bwAppNameHeader.* | cut -d ":" -f2 | tr -d '[[:space:]]' | sed "s/\\\\\r'//g" | sed "s/$'//g"`
if [ "$DISABLE_BWCE_EAR_VALIDATION" != true ]; then
bwEditionHeaderStr=`grep -E $bwEdition ${manifest}`
res=$?
if [ ${res} -eq 0 ]; then
print_Debug " "
else
echo "ERROR: Application [$bwBundleAppName] is not supported in TIBCO BusinessWorks Container Edition. Convert this application to TIBCO BusinessWorks Container Edition using TIBCO Business Studio Container Edition. Refer Conversion Guide for more details."
exit 1
fi
else
print_Debug "BWCE EAR Validation disabled."
fi
for name in $(find $BUILD_DIR -path $BUILD_DIR/tibco.home -prune -o -type f -iname "*.jar");
do
if [[ $name == *.jar ]]; then
mkdir -p $BUILD_DIR/temp
unzip -o -q $name -d $BUILD_DIR/temp
MANIFESTMF=$BUILD_DIR/temp/META-INF/MANIFEST.MF
bwcePaletteStr=`tr -d '\n\r ' < ${MANIFESTMF} | grep -E 'bw.rv'`
palette_res=$?
bwcePolicyStr=`tr -d '\n\r ' < ${MANIFESTMF} | grep -E 'bw.authxml|bw.cred|bw.ldap|bw.wss|bw.dbauth|bw.kerberos|bw.realmdb|bw.ldaprealm|bw.userid'`
policy_res=$?
rm -rf $BUILD_DIR/temp
if [ ${palette_res} -eq 0 ]; then
echo "ERROR: Application [$bwBundleAppName] is using unsupported RV palette and can not be deployed in Docker. Rebuild your application for Docker using TIBCO Business Studio Container Edition."
exit 1
fi
if [ ${policy_res} -eq 0 ]; then
POLICY_ENABLED="true"
break
fi
fi
done
fi
arr=$(echo $bwAppProfileStr | tr "/" "\n")
for x in $arr
do
case "$x" in
*substvar)
defaultProfile=$x;;esac
done
if [ -z ${BW_PROFILE:=${defaultProfile}} ]; then
echo "BW_PROFILE is unset. Set it to $defaultProfile";
else
case $BW_PROFILE in
*.substvar ) ;;
* ) BW_PROFILE="${BW_PROFILE}.substvar";;esac
echo "BW_PROFILE is set to '$BW_PROFILE'";
fi
}
checkPolicy()
{
if [[ $POLICY_ENABLED = "true" ]]; then
if [ -e ${appnodeConfigFile} ]; then
printf '%s\n' "bw.governance.enabled=true" >> $appnodeConfigFile
print_Debug "Set bw.governance.enabled=true"
fi
fi
}
setLogLevel()
{
logback=$BWCE_HOME/tibco.home/bw*/*/config/logback.xml
if [[ ${CUSTOM_LOGBACK} ]]; then
logback_custom=/resources/addons/custom-logback/logback.xml
if [ -e ${logback_custom} ]; then
cp ${logback} `ls $logback`.original.bak && cp -f ${logback_custom} ${logback}
echo "Using Custom Logback file"
else
echo "Custom Logback file not found. Using the default logback file"
fi
fi
if [[ ${BW_LOGLEVEL} && "${BW_LOGLEVEL,,}"="debug" ]]; then
if [ -e ${logback} ]; then
sed -i.bak "/<root/ s/\".*\"/\"$BW_LOGLEVEL\"/Ig" $logback
echo "The loglevel is set to $BW_LOGLEVEL level"
fi
else
sed -i.bak "/<root/ s/\".*\"/\"ERROR\"/Ig" $logback
fi
}
checkEnvSubstituteConfig()
{
bwappnodeTRA=$BWCE_HOME/tibco.home/bw*/*/bin/bwappnode.tra
bwappnodeFile=$BWCE_HOME/tibco.home/bw*/*/bin/bwappnode
#appnodeConfigFile=$BWCE_HOME/tibco.home/bw*/*/config/appnode_config.ini
manifest=/tmp/META-INF/MANIFEST.MF
bwAppNameHeader="Bundle-SymbolicName"
bwBundleAppName=`while read line; do printf "%q\n" "$line"; done<${manifest} | awk '/.*:/{printf "%s%s", (NR==1)?"":RS,$0;next}{printf "%s", FS $0}END{print ""}' | grep -o $bwAppNameHeader.* | cut -d ":" -f2 | tr -d '[[:space:]]' | sed "s/\\\\\r'//g" | sed "s/$'//g"`
export BWCE_APP_NAME=$bwBundleAppName
if [ -e ${bwappnodeTRA} ]; then
sed -i 's?-Djava.class.path=?-Djava.class.path=$ADDONS_HOME/lib:?' $bwappnodeTRA
print_Debug "Appended ADDONS_HOME/lib in bwappnode.tra file"
fi
if [ -e ${bwappnodeFile} ]; then
sed -i 's?-Djava.class.path=?-Djava.class.path=$ADDONS_HOME/lib:?' $bwappnodeFile
print_Debug "Appended ADDONS_HOME/lib in bwappnode file"
fi
if [[ ${BW_JAVA_OPTS} ]]; then
if [ -e ${bwappnodeTRA} ]; then
sed -i.bak "/java.extended.properties/s/$/ ${BW_JAVA_OPTS}/" $bwappnodeTRA
print_Debug "Appended $BW_JAVA_OPTS to java.extend.properties"
fi
fi
if [[ ${BW_ENGINE_THREADCOUNT} ]]; then
if [ -e ${appnodeConfigFile} ]; then
printf '%s\n' "bw.engine.threadCount=$BW_ENGINE_THREADCOUNT" >> $appnodeConfigFile
print_Debug "set BW_ENGINE_THREADCOUNT to $BW_ENGINE_THREADCOUNT"
fi
fi
if [[ ${BW_ENGINE_STEPCOUNT} ]]; then
if [ -e ${appnodeConfigFile} ]; then
printf '%s\n' "bw.engine.stepCount=$BW_ENGINE_STEPCOUNT" >> $appnodeConfigFile
print_Debug "set BW_ENGINE_STEPCOUNT to $BW_ENGINE_STEPCOUNT"
fi
fi
if [[ ${BW_APPLICATION_JOB_FLOWLIMIT} ]]; then
if [ -e ${appnodeConfigFile} ]; then
printf '%s\n' "bw.application.job.flowlimit.$bwBundleAppName=$BW_APPLICATION_JOB_FLOWLIMIT" >> $appnodeConfigFile
print_Debug "set BW_APPLICATION_JOB_FLOWLIMIT to $BW_APPLICATION_JOB_FLOWLIMIT"
fi
fi
if [[ ${BW_COMPONENT_JOB_FLOWLIMIT} ]]; then
if [ -e ${appnodeConfigFile} ]; then
IFS=';' # space is set as delimiter
read -ra processConfigurationList <<< "${BW_COMPONENT_JOB_FLOWLIMIT}" # str is read into an array as tokens separated by IFS
for process in "${processConfigurationList[@]}"; do # access each element of array
echo "Setting flow limit for $process"
IFS=':' # space is set as delimiter
read -ra processConfiguration <<< "$process" # str is read into an array as tokens separated by IFS
printf '%s\n' "bw.application.job.flowlimit.$bwBundleAppName.${processConfiguration[0]}=${processConfiguration[1]}" >> $appnodeConfigFile
print_Debug "set bw.application.job.flowlimit.$bwBundleAppName.${processConfiguration[0]} to ${processConfiguration[1]}"
done
fi
fi
if [[ ${BW_APP_MONITORING_CONFIG} ]]; then
if [ -e ${appnodeConfigFile} ]; then
sed -i 's/bw.frwk.event.subscriber.metrics.enabled=false/bw.frwk.event.subscriber.metrics.enabled=true/g' $appnodeConfigFile
print_Debug "set bw.frwk.event.subscriber.metrics.enabled to true"
fi
fi
if [[ $BW_LOGLEVEL = "DEBUG" ]]; then
if [[ ${BW_APPLICATION_JOB_FLOWLIMIT} ]] || [[ ${BW_ENGINE_STEPCOUNT} ]] || [[ ${BW_ENGINE_THREADCOUNT} ]] || [[ ${BW_APP_MONITORING_CONFIG} ]]; then
echo "---------------------------------------"
cat $appnodeConfigFile
echo "---------------------------------------"
fi
fi
}
checkPlugins()
{
pluginFolder=/resources/addons/plugins
if [ -d ${pluginFolder} ] && [ "$(ls $pluginFolder)" ]; then
print_Debug "Adding Plug-in Jars"
echo -e "name=Addons Factory\ntype=bw6\nlayout=bw6ext\nlocation=$BWCE_HOME/tibco.home/addons" > `echo $BWCE_HOME/tibco.home/bw*/*/ext/shared`/addons.link
for name in $(find $pluginFolder -type f);
do
# filter out hidden files
if [[ "$(basename $name )" != .* ]]; then
unzip -q -o $name -d $BWCE_HOME/plugintmp/
mkdir -p $BWCE_HOME/tibco.home/addons/runtime/plugins/ && mv $BWCE_HOME/plugintmp/runtime/plugins/* "$_"
mkdir -p $BWCE_HOME/tibco.home/addons/lib/ && mv $BWCE_HOME/plugintmp/lib/*.ini "$_"${name##*/}.ini
mkdir -p $BWCE_HOME/tibco.home/addons/lib/ && mv $BWCE_HOME/plugintmp/lib/*.jar "$_" 2> /dev/null || true
mkdir -p $BWCE_HOME/tibco.home/addons/bin/ && mv $BWCE_HOME/plugintmp/bin/* "$_" 2> /dev/null || true
find $BWCE_HOME/plugintmp/* -type d ! \( -name "runtime" -o -name "bin" -o -name "lib" \) -exec mv {} / \; 2> /dev/null
rm -rf $BWCE_HOME/plugintmp/
fi
done
fi
}
checkLibs()
{
BW_VERSION=`ls $BWCE_HOME/tibco.home/bw*/`
libFolder=/resources/addons/lib
if [ -d ${libFolder} ] && [ "$(ls $libFolder)" ]; then
print_Debug "Adding additional libs"
for name in $(find $libFolder -type f);
do
if [[ "$(basename $name)" = 'libsunec.so' ]]; then
print_Debug "libsunec.so File found..."
JRE_VERSION=`ls $BWCE_HOME/tibco.home/tibcojre64/`
JRE_LOCATION=$BWCE_HOME/tibco.home/tibcojre64/$JRE_VERSION
SUNEC_LOCATION=$JRE_LOCATION/lib/amd64
cp -vf $name $SUNEC_LOCATION
else
# filter out hidden files
if [[ "$(basename $name )" != .* ]]; then
mkdir -p $BWCE_HOME/tibco.home/addons/lib/
unzip -q $name -d $BWCE_HOME/tibco.home/addons/lib/
fi
fi
done
fi
}
checkCerts()
{
certsFolder=/resources/addons/certs
if [ -d ${certsFolder} ] && [ "$(ls $certsFolder)" ]; then
JRE_VERSION=`ls $BWCE_HOME/tibco.home/tibcojre64/`
JRE_LOCATION=$BWCE_HOME/tibco.home/tibcojre64/$JRE_VERSION
certsStore=$JRE_LOCATION/lib/security/cacerts
chmod +x $JRE_LOCATION/bin/keytool
for name in $(find $certsFolder -type f);
do
# filter out hidden files
if [[ "$(basename $name )" != .* && "$(basename $name )" != *.jks ]]; then
certsFile=$(basename $name )
print_Debug "Importing $certsFile into java truststore"
aliasName="${certsFile%.*}"
$JRE_LOCATION/bin/keytool -import -trustcacerts -keystore $certsStore -storepass changeit -noprompt -alias $aliasName -file $name
fi
done
fi
}
checkAgents()
{
agentFolder=/resources/addons/monitor-agents
if [ -d ${agentFolder} ] && [ "$(ls $agentFolder)" ]; then
print_Debug "Adding monitoring jars"
for name in $(find $agentFolder -type f);
do
# filter out hidden files
if [[ "$(basename $name )" != .* ]];then
mkdir -p $BWCE_HOME/agent/
unzip -q $name -d $BWCE_HOME/agent/
fi
done
fi
}
memoryCalculator()
{
if [[ ${MEMORY_LIMIT} ]]; then
configured_MEM=$(expr `cat /sys/fs/cgroup/memory/memory.limit_in_bytes` / 1024 / 1024)
configured_MEM_orig=$configured_MEM
if [[ ${MEMORY_DYNAMIC_LIMIT} ]]; then
sys_MEM=$(expr $configured_MEM \* ${MEMORY_DYNAMIC_LIMIT} / 100)
system_MEM=`printf "%.0f" $sys_MEM`
configured_MEM_temp=$(expr $configured_MEM - $system_MEM)
if [[ $configured_MEM_temp -gt 128 ]]; then
configured_MEM=$configured_MEM_temp
fi
elif [[ ${MEMORY_FIXED_LIMIT} ]]; then
configured_MEM_temp=$(expr $configured_MEM - ${MEMORY_FIXED_LIMIT} )
if [[ $configured_MEM_temp -gt 128 ]]; then
configured_MEM=$configured_MEM_temp
fi
fi
if [[ $configured_MEM -eq $configured_MEM_orig ]]; then
configured_MEM_temp=$(expr $configured_MEM - 128)
if [[ $configured_MEM_temp -gt 128 ]]; then
configured_MEM=$configured_MEM_temp
fi
fi
print_Debug "Maximum memory calculated in a dynamic way to a value [$configured_MEM]"
thread_Stack=$((memory_Number))
JAVA_PARAM="-Xmx"$configured_MEM"M -Xms128M -Xss512K"
export BW_JAVA_OPTS=$JAVA_PARAM" "$BW_JAVA_OPTS
fi
}
applyDefaultJVMHeapParams(){
DEFAULT_JVM_HEAP_PARAMS="-Xmx1024M -Xms128M"
if [[ ${BW_JAVA_OPTS} && ${BW_JAVA_OPTS} != *"Xm"* || -z ${BW_JAVA_OPTS} ]]; then
export BW_JAVA_OPTS=$DEFAULT_JVM_HEAP_PARAMS" "$BW_JAVA_OPTS
fi
}
checkJMXConfig()
{
if [[ ${BW_JMX_CONFIG} ]]; then
if [[ $BW_JMX_CONFIG == *":"* ]]; then
JMX_HOST=${BW_JMX_CONFIG%%:*}
JMX_PORT=${BW_JMX_CONFIG#*:}
else
JMX_HOST="127.0.0.1"
JMX_PORT=$BW_JMX_CONFIG
fi
JMX_PARAM="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port="$JMX_PORT" -Dcom.sun.management.jmxremote.rmi.port="$JMX_PORT" -Djava.rmi.server.hostname="$JMX_HOST" -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false "
export BW_JAVA_OPTS=$BW_JAVA_OPTS" "$JMX_PARAM
fi
}
checkJavaGCConfig()
{
if [[ ${BW_JAVA_GC_OPTS} ]]; then
print_Debug $BW_JAVA_GC_OPTS
else
export BW_JAVA_GC_OPTS="-XX:+UseG1GC"
fi
}
checkJAVAHOME()
{
if [[ ${JAVA_HOME} ]]; then
print_Debug $JAVA_HOME
else
export JAVA_HOME=$BWCE_HOME/tibco.home/tibcojre64/1.8.0
fi
}
checkThirdPartyInstallations()
{
installFolder=/resources/addons/thirdparty-installs
if [ -d ${installFolder} ] && [ "$(ls $installFolder)" ]; then
mkdir -p $BWCE_HOME/tibco.home/thirdparty-installs
for f in "$installFolder"/*; do
if [ -d $f ]
then
cp -R "$f" $BWCE_HOME/tibco.home/thirdparty-installs
else
if [ "${f##*.}" == "zip" ]
then
unzip -q "$f" -d $BWCE_HOME/tibco.home/thirdparty-installs/$(basename "$f" .zip);
else
echo "Can not unzip $f. Not a valid ZIP file"
fi
fi
done;
fi
}
setupThirdPartyInstallationEnvironment()
{
INSTALL_DIR=$BWCE_HOME/tibco.home/thirdparty-installs
if [ -d "$INSTALL_DIR" ]; then
for f in "$INSTALL_DIR"/*; do
if [ -d $f ]
then
if [ -d "$f"/lib ]; then
export LD_LIBRARY_PATH="$f"/lib:$LD_LIBRARY_PATH
fi
setupFile=`ls "$f"/*.sh`
if [ -f "$setupFile" ]; then
chmod 755 "$setupFile"
source "$setupFile" "$f"
fi
fi
done;
fi
}
appnodeConfigFile=$BWCE_HOME/tibco.home/bw*/*/config/appnode_config.ini
POLICY_ENABLED="false"
checkJAVAHOME
checkJMXConfig
checkJavaGCConfig
if [ ! -d $BWCE_HOME/tibco.home ];
then
unzip -qq /resources/bwce-runtime/bwce*.zip -d $BWCE_HOME
rm -rf /resources/bwce-runtime/bwce*.zip 2> /dev/null
chmod 755 $BWCE_HOME/tibco.home/bw*/*/bin/startBWAppNode.sh
chmod 755 $BWCE_HOME/tibco.home/bw*/*/bin/bwappnode
chmod 755 $BWCE_HOME/tibco.home/tibcojre64/*/bin/java
chmod 755 $BWCE_HOME/tibco.home/tibcojre64/*/bin/javac
sed -i "s#_APPDIR_#$APPDIR#g" $BWCE_HOME/tibco.home/bw*/*/bin/bwappnode.tra
sed -i "s#_APPDIR_#$APPDIR#g" $BWCE_HOME/tibco.home/bw*/*/bin/bwappnode
touch $BWCE_HOME/keys.properties
mkdir $BWCE_HOME/tmp
addonFolder=/resources/addons
if [ -d ${addonFolder} ]; then
checkPlugins
checkAgents
checkLibs
checkCerts
checkThirdPartyInstallations
jarFolder=/resources/addons/jars
if [ -d ${jarFolder} ] && [ "$(ls $jarFolder)" ]; then
#Copy jars to Hotfix
cp -r /resources/addons/jars/* `echo $BWCE_HOME/tibco.home/bw*/*`/system/hotfix/shared
fi
fi
ln -s /*.ear `echo $BWCE_HOME/tibco.home/bw*/*/bin`/bwapp.ear
sed -i.bak "s#_APPDIR_#$BWCE_HOME#g" $BWCE_HOME/tibco.home/bw*/*/config/appnode_config.ini
unzip -qq `echo $BWCE_HOME/tibco.home/bw*/*/bin/bwapp.ear` -d /tmp
setLogLevel
memoryCalculator
applyDefaultJVMHeapParams
fi
checkProfile
checkPolicy
setupThirdPartyInstallationEnvironment
checkEnvSubstituteConfig
if [ -f /*.substvar ]; then
cp -f /*.substvar $BWCE_HOME/tmp/pcf.substvar # User provided profile
else
cp -f /tmp/META-INF/$BW_PROFILE $BWCE_HOME/tmp/pcf.substvar
fi
$JAVA_HOME/bin/java -cp `echo $BWCE_HOME/tibco.home/bw*/*/system/shared/com.tibco.bwce.profile.resolver_*.jar`:`echo $BWCE_HOME/tibco.home/bw*/*/system/shared/com.tibco.tpcl.com.fasterxml.jackson_*`/*:`echo $BWCE_HOME/tibco.home/bw*/*/system/shared/com.tibco.bw.tpcl.org.codehaus.jettison_*`/*:$BWCE_HOME:$JAVA_HOME/lib -DBWCE_APP_NAME=$bwBundleAppName com.tibco.bwce.profile.resolver.Resolver
STATUS=$?
if [ $STATUS == "1" ]; then
exit 1 # terminate and indicate error
fi