22
33# *******************************************************************************
44# Licensed Materials - Property of HCL
5- # (c) Copyright HCL Technologies Ltd. 2021 . All Rights Reserved.
5+ # (c) Copyright HCL Technologies Ltd. 2023 . All Rights Reserved.
66#
77# Note to U.S. Government Users Restricted Rights:
88# Use, duplication or disclosure restricted by GSA ADP Schedule
@@ -18,21 +18,22 @@ usage() {
1818 echo " Commands:"
1919 echo " load Loads AIDA's container images"
2020 echo " set-custom-port Sets a custom port to access AIDA (default is 9432)"
21- echo " set-shards Sets the number of shards for Elasticsearch (default is 1)"
2221 echo " build-start Builds, creates and starts AIDA's containers (reccommended for the first start)"
2322 echo " build Builds and creates AIDA's containers (without starting them)"
2423 echo " start Starts AIDA's containers (without building and creating them, before the first start run build or directly use build-start)"
24+ echo " up Recreates only containers if the configuration changed after last start (reccommended for debug)"
2525 echo " stop Stops AIDA's containers"
2626 echo " restart Restarts AIDA's containers"
2727 echo " down Removes AIDA's containers (but not volumes)"
2828 echo " down-volumes Removes AIDA's containers and volumes"
2929 echo " first-start Helps setting up AIDA configuration for the first start"
30- echo " add-credentials Lets you add credentials to connect to an OpenMetrics server"
30+ echo " add-credentials Lets you add credentials to connect to a Workload Automation server"
3131 echo " update-credentials Lets you update previously added credentials"
3232 echo " delete-credentials Lets you delete previously added credentials"
3333 echo " "
3434 echo " Options:"
3535 echo " --noexporter Excludes the exporter service when executing the command"
36+ echo " --debug Enables debug mode"
3637}
3738
3839# Use "docker compose" if "docker-compose" doesn't exist.
@@ -43,41 +44,45 @@ if ! type docker-compose >& /dev/null; then
4344fi
4445
4546load () {
46- docker load -i ../aida-images.tgz
47+ for f in ../aida-* .t * ; do cat $f | docker load ; done
4748}
4849
4950start () {
50- docker- compose -f $1 start
51+ docker compose -f $yml start
5152}
5253
5354stop () {
54- docker- compose -f $1 stop
55+ docker compose -f $yml stop
5556}
5657
5758restart () {
58- docker- compose -f $1 restart
59+ docker compose -f $yml restart
5960}
6061
6162down () {
62- docker- compose -f $1 down
63+ docker compose -f $yml down
6364}
6465
6566down_volumes () {
66- docker- compose -f $1 down --volumes $2
67+ docker compose -f $yml down --volumes
6768}
6869
6970build () {
70- docker- compose -f $1 build --build-arg REGISTRY=" hclcr.io/wa" --build-arg VERSION=10.1.0.00
71- docker- compose -f $1 up --no-start
71+ docker compose -f $yml build --build-arg REGISTRY=' hclcr.io/wa/workload-automation/hcl- ' --build-arg VERSION=10.2.3
72+ docker compose -f $yml up --no-start
7273}
7374
7475build_start () {
75- docker-compose -f $1 build --build-arg REGISTRY=" hclcr.io/wa" --build-arg VERSION=10.1.0.00 $2
76- docker-compose -f $1 up -d $2
76+ docker compose -f $yml build --build-arg REGISTRY=' hclcr.io/wa/workload-automation/hcl-' --build-arg VERSION=10.2.3 $1
77+ docker compose -f $yml up -d $1
78+ }
79+
80+ up () {
81+ docker compose -f $yml up -d
7782}
7883
7984first_start () {
80- read -p " Do you want to add the credentials to connect to an OpenMetrics server? [Y/n]: " -n 1 -r
85+ read -p " Do you want to add the credentials to connect to an Workload Automation server? [Y/n]: " -n 1 -r
8186 echo " "
8287
8388 case " $REPLY " in
@@ -104,31 +109,17 @@ first_start() {
104109 echo " "
105110 ;;
106111 esac
107-
108- read -p " Do you want to change the default number of shards (1) of Elasticsearch? [Y/n]: " -n 1 -r
109- echo " "
110-
111- case " $REPLY " in
112- y|Y|" " )
113- set_shards $common
114- ;;
115-
116- * )
117- echo " Leaving the default shard count (1) unchanged."
118- echo " "
119- ;;
120- esac
121112}
122113
123114start_config () {
124- if ! docker image inspect " hclcr.io/wa/aida-config:10.1.0.00 " >& /dev/null; then
115+ if ! docker image inspect " hclcr.io/wa/workload-automation/hcl- aida-config:10.2.3 " >& /dev/null; then
125116 echo " Loading configuration container image..."
126- docker load -i ../aida-images.tgz
117+ for f in ../aida-* .t * ; do cat $f | docker load ; done
127118 fi
128119
129120 echo " Starting configuration container..."
130121
131- docker- compose --profile config -f $yml up -d config
122+ docker compose --profile config -f $yml up -d config
132123
133124 if [ $? -ne 0 ]; then
134125 echo " "
@@ -139,36 +130,36 @@ start_config() {
139130 echo " "
140131}
141132
142- start_elasticsearch () {
143- echo " Starting Elasticsearch to store credentials..."
133+ start_opensearch () {
134+ echo " Starting database to store credentials..."
144135
145- build_start $yml " es"
136+ build_start " es"
146137
147138 if [ $? -ne 0 ]; then
148139 echo " "
149- echo " ERROR: Failed to start Elasticsearch "
140+ echo " ERROR: Failed to start Opensearch "
150141 exit
151142 fi
152143
153144 echo " "
154145}
155146
156147add_credentials () {
157- start_elasticsearch
148+ start_opensearch
158149
159- docker- compose --profile config exec config /config.sh add_credentials
150+ docker compose --profile config exec config /config.sh add_credentials
160151}
161152
162153update_credentials () {
163- start_elasticsearch
154+ start_opensearch
164155
165- docker- compose --profile config exec config /config.sh update_credentials
156+ docker compose --profile config exec config /config.sh update_credentials
166157}
167158
168159delete_credentials () {
169- start_elasticsearch
160+ start_opensearch
170161
171- docker- compose --profile config exec config /config.sh delete_credentials
162+ docker compose --profile config exec config /config.sh delete_credentials
172163}
173164
174165set_custom_port () {
@@ -193,13 +184,21 @@ set_custom_port() {
193184 OK=0
194185 done
195186
196- # Changes the port in the docker-compose yaml file.
197- if sed -Ezi " s/ports:(\s+)- \" [0-9]+:([0-9]+)\" /ports:\1- \" $port :\2\" /" $1 ; then
187+ # Changes the port in the docker-compose yaml file.
188+ if sed -Ezi " s/ports:(\s+)- \" [0-9]+:[0-9]+\" /ports:\1- \" $port :$port \" /" $1 &&
189+ sed -Ezi " s/listen(\s+)[0-9]+/listen\1$port /" " ./nginx/default.conf" &&
190+ sed -Ezi " s,HOST_PORT=[0-9]+,HOST_PORT=$port ,g" " common.env" ; then
198191 echo " Port successfully changed!"
199192 else
200193 echo " ERROR: Could not change the port"
201194 fi
195+ sed -Ezi " s,hostname-port=[0-9]+,hostname-port=${port} ,g" ./keycloak/keycloak.conf
196+
197+ docker cp ./keycloak/keycloak.conf aida-keycloak:/opt/keycloak/conf/keycloak.conf
198+ up
202199
200+ docker cp ./nginx/default.conf aida-nginx:/etc/nginx/conf.d/default.conf.template
201+ docker restart aida-nginx
203202 echo " "
204203}
205204
@@ -221,10 +220,35 @@ set_shards() {
221220 echo " "
222221}
223222
223+
224+
225+ get_machine_address (){
226+ ip_already_setted=$( cat common.env | grep -E " HOST_IP=[0-9.]+" )
227+
228+ if [ -n " $ip_already_setted " ]; then
229+ return 0
230+ fi
231+ machine_address=$( ip -4 -o -br address show | head -2 | tail -1 | tr -s ' ' | cut -d ' ' -f 3 | cut -d ' /' -f 1)
232+ if [ $? -ne 0 ] || [ -z " $machine_address " ]; then
233+ echo " "
234+ echo " Ip address of the machine not found,the IP of the machine will not be setted automatically"
235+ return 0
236+ fi
237+
238+ if ping -q -c 1 -w 2 $machine_address 2>&1 > /dev/null; then
239+ echo " Found IP Address $machine_address , it will be setted automatically"
240+ sed -i " s,EXTERNAL_HOSTNAME=,EXTERNAL_HOSTNAME=$machine_address ,g" common.env
241+ else
242+ echo " Found IP Address $machine_address ,but can't reach it"
243+ echo " IP Address $machine_address . Will not be setted automatically"
244+ fi
245+
246+ }
247+
224248cleanup () {
225249 echo " Removing configuration container..."
226250
227- docker- compose -f $yml rm -svf " config"
251+ docker compose -f $yml rm -svf " config"
228252
229253 if [ $? -ne 0 ]; then
230254 echo " "
@@ -235,8 +259,58 @@ cleanup() {
235259 echo " "
236260}
237261
262+ check_license (){
263+ if [ $( grep -Fx " LICENSE=accept" common.env) ]; then
264+ return
265+ fi
266+
267+ less Licenses/license
268+
269+ LICENSE_CONFIRMATION=" Y"
270+ read -p " Confirm License [Y/n] " LICENSE_CONFIRMATION
271+ if [[ $LICENSE_CONFIRMATION == " Y" || $LICENSE_CONFIRMATION == " y" ]]; then
272+ sed -i " s,LICENSE=notaccepted,LICENSE=accept,g" common.env
273+ else
274+ echo You need to accept the license before using AIDA
275+ exit 1
276+ fi
277+ }
278+
279+ dump_log (){
280+ LOG_DIR=" docker_logs"
281+ mkdir -p $LOG_DIR
282+
283+ echo " Searching for Aida Docker Containers"
284+ set -f
285+ IFS=" "
286+ CONTAINERS=$( docker ps -a | grep -oh " aida-\w*" | tr ' \n' ' ' )
287+ CONTAINERS_CLEAN=()
288+
289+ for container in $CONTAINERS ; do
290+ if [[ " $container " != * " nginx" * ]] && [[ " $container " != * " hcl" * ]] && [[ " $container " != * " config" * ]]
291+ then
292+ CONTAINERS_CLEAN+=(" $container " )
293+ fi
294+ done
295+
296+ if [ ${# CONTAINERS_CLEAN[@]} -eq 0 ]; then
297+ echo " There are no containers builded"
298+ echo " Please before calling dump build the containters with AIDA.sh build-start"
299+ exit 2
300+ fi
301+
302+ for container in $CONTAINERS_CLEAN ; do
303+ if [[ " $container " != * " nginx" * ]] && [[ " $container " != * " hcl" * ]]
304+ then
305+ docker logs $container >> " $LOG_DIR /$container .log" 2>&1
306+ fi
307+ done
308+
309+ docker cp aida-nginx:/var/log/nginx $LOG_DIR /
310+ }
311+
238312# Parse options
239- if ! options=$( getopt -n " $0 " --options " h" --long " help,noexporter" -- " $@ " ) ; then
313+ if ! options=$( getopt -n " $0 " --options " h" --long " help,noexporter,debug,dev " -- " $@ " ) ; then
240314 usage
241315 exit
242316fi
@@ -246,6 +320,8 @@ eval set -- "$options"
246320# Use options
247321noexporter=false
248322yml=" docker-compose.yml"
323+ debug_yml=" docker-compose.debug.yml"
324+ dev_yml=" docker-compose.dev.yml"
249325common=" common.env"
250326while true ; do
251327 case " $1 " in
@@ -254,6 +330,14 @@ while true; do
254330 yml=" docker-compose-noexporter.yml"
255331 shift
256332 ;;
333+ --debug)
334+ yml=" $yml -f $debug_yml "
335+ shift
336+ ;;
337+ --dev)
338+ yml=" $yml -f $dev_yml "
339+ shift
340+ ;;
257341 -h|--help)
258342 usage
259343 exit
@@ -276,6 +360,8 @@ if [ "$#" -ne 1 ]; then
276360fi
277361
278362# Start config container
363+ check_license
364+ # get_machine_address
279365start_config
280366
281367# Clean up containers if the script exits
@@ -291,36 +377,36 @@ case "$1" in
291377 set_custom_port $yml
292378 ;;
293379
294- set-shards)
295- set_shards $common
296- ;;
297-
298380 start)
299- start $yml
381+ start
300382 ;;
301383
302384 stop)
303- stop $yml
385+ stop
304386 ;;
305387
306388 restart)
307- restart $yml
389+ restart
308390 ;;
309391
310392 down)
311- down $yml
393+ down
312394 ;;
313395
314396 down-volumes)
315- down_volumes $yml
397+ down_volumes
316398 ;;
317399
318400 build)
319- build $yml
401+ build
320402 ;;
321403
322404 build-start)
323- build_start $yml
405+ build_start
406+ ;;
407+
408+ up)
409+ up
324410 ;;
325411
326412 first-start)
@@ -338,7 +424,9 @@ case "$1" in
338424 delete-credentials)
339425 delete_credentials
340426 ;;
341-
427+ dump)
428+ dump_log
429+ ;;
342430 -h|--help|* )
343431 usage
344432 exit
0 commit comments