From def11937b8a8e8b372783336ec57f5e2cf840961 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Wed, 24 Aug 2022 15:51:19 -0600 Subject: [PATCH 1/4] improve rollback logic --- functions/update_apps.sh | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/functions/update_apps.sh b/functions/update_apps.sh index 8a0c353f..a72f54d9 100644 --- a/functions/update_apps.sh +++ b/functions/update_apps.sh @@ -192,7 +192,7 @@ if [[ $rollback == "true" || "$startstatus" == "STOPPED" ]]; then while true do status=$(grep "^$app_name," all_app_status | awk -F ',' '{print $2}') - if [[ $count -lt 1 && $status == "ACTIVE" && "$(grep "^$app_name," deploying 2>/dev/null | awk -F ',' '{print $2}')" != "DEPLOYING" ]]; then # If status shows up as Active or Stopped on the first check, verify that. Otherwise it may be a false report.. + if [[ $count -lt 1 && $status == "ACTIVE" && "$(grep "^$app_name," deploying 2>/dev/null | awk -F ',' '{print $2}')" != "DEPLOYING" ]]; then # If status shows up as Active or Stopped on the first check, verify that. Otherwise it may be a false report.. [[ "$verbose" == "true" ]] && echo_array+=("Verifying $status..") before_loop=$(head -n 1 all_app_status) current_loop=0 @@ -229,10 +229,18 @@ if [[ $rollback == "true" || "$startstatus" == "STOPPED" ]]; then echo_array+=("If this is a slow starting application, set a higher timeout with -t") echo_array+=("If this applicaion is always DEPLOYING, you can disable all probes under the Healthcheck Probes Liveness section in the edit configuration") echo_array+=("Reverting update..") - midclt call chart.release.rollback "$app_name" "{\"item_version\": \"$rollback_version\"}" &> /dev/null || { echo_array+=("Error: Failed to rollback $app_name") ; break ; } - [[ "$startstatus" == "STOPPED" ]] && failed="true" && after_update_actions #run back after_update_actions function if the app was stopped prior to update echo "$app_name,$new_full_ver" >> failed - break + if rollback_app ; then + echo_array+=("Rolled Back") + else + echo_array+=("Error: Failed to rollback $app_name\nAbandoning") + echo_array + return 1 + fi + failed="true" + SECONDS=0 + count=0 + continue #run back after_update_actions function if the app was stopped prior to update else echo_array+=("Error: Run Time($SECONDS) for $app_name has exceeded Timeout($timeout)") echo_array+=("The application failed to be ACTIVE even after a rollback") @@ -251,6 +259,7 @@ if [[ $rollback == "true" || "$startstatus" == "STOPPED" ]]; then echo_array+=("If this is a slow starting application, set a higher timeout with -t") echo_array+=("If this applicaion is always DEPLOYING, you can disable all probes under the Healthcheck Probes Liveness section in the edit configuration") echo_array+=("Manual intervention is required\nStopping, then Abandoning") + echo "$app_name,$new_full_ver" >> failed if stop_app ; then echo_array+=("Stopped") else @@ -272,6 +281,26 @@ echo_array export -f after_update_actions +rollback_app(){ +count=0 +while [[ $update_avail != "true" ]] +do + update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}') + if [[ $count -gt 2 ]]; then # If failed to rollback app 3 times, return failure to parent shell + return 1 + elif ! cli -c "app chart_release rollback release_name=\"$app_name\" rollback_options={\"item_version\": \"$rollback_version\"}" &> /dev/null ; then + before_loop=$(head -n 1 all_app_status) + ((count++)) + until [[ $(head -n 1 all_app_status) != "$before_loop" ]] # Upon failure, wait for status update before continuing + do + sleep 1 + done + else + break + fi +done +} + echo_array(){ #Dump the echo_array, ensures all output is in a neat order. for i in "${echo_array[@]}" From fbdcf88a9995a31f27e5e6720c4cb4a89d3df970 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Wed, 24 Aug 2022 16:16:34 -0600 Subject: [PATCH 2/4] fix rollback_app logic --- functions/update_apps.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/functions/update_apps.sh b/functions/update_apps.sh index a72f54d9..d695e4a2 100644 --- a/functions/update_apps.sh +++ b/functions/update_apps.sh @@ -283,7 +283,8 @@ export -f after_update_actions rollback_app(){ count=0 -while [[ $update_avail != "true" ]] +update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}') +while [[ $update_avail == "false" ]] do update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}') if [[ $count -gt 2 ]]; then # If failed to rollback app 3 times, return failure to parent shell From c1dc53c23166c549b07be5d1dc750a967244b485 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Wed, 24 Aug 2022 16:39:08 -0600 Subject: [PATCH 3/4] add support back for container updates --- functions/update_apps.sh | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/functions/update_apps.sh b/functions/update_apps.sh index d695e4a2..282e5c03 100644 --- a/functions/update_apps.sh +++ b/functions/update_apps.sh @@ -16,7 +16,7 @@ rm deploying 2>/dev/null rm finished 2>/dev/null while true do - if while_status=$(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,status' 2>/dev/null) ; then + if while_status=$(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,container_images_update_available,status' 2>/dev/null) ; then ((while_count++)) [[ -z $while_status ]] && continue || echo -e "$while_count\n$while_status" > all_app_status mapfile -t deploying_check < <(grep ",DEPLOYING," all_app_status) @@ -107,7 +107,6 @@ if [[ $stop_before_update == "true" && "$startstatus" != "STOPPED" ]]; then # C else echo_array+=("Error: Failed to stop $app_name") echo_array - final_check return 1 fi fi @@ -117,16 +116,13 @@ if update_app ;then else echo_array+=("Failed to update\nManual intervention may be required") echo_array - final_check return fi if grep -qs "^$app_name,true" external_services ; then echo_array - final_check return else after_update_actions - final_check fi } export -f pre_process @@ -136,12 +132,13 @@ update_app(){ current_loop=0 while true do - update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}') - if [[ $update_avail == "true" ]]; then + app_update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}') + cont_update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $6}') + if [[ $app_update_avail == "true" || $cont_update_avail == "true" ]]; then if ! cli -c 'app chart_release upgrade release_name=''"'"$app_name"'"' &> /dev/null ; then before_loop=$(head -n 1 all_app_status) current_loop=0 - until [[ "$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}')" != "$update_avail" ]] # Wait for a specific change to app status, or 3 refreshes of the file to go by. + until [[ "$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}')" != "$app_update_avail" || "$(grep "^$app_name," all_app_status | awk -F ',' '{print $6}')" != "$cont_update_avail" ]] # Wait for a specific change to app status, or 3 refreshes of the file to go by. do if [[ $current_loop -gt 2 ]]; then cli -c 'app chart_release upgrade release_name=''"'"$app_name"'"' &> /dev/null || return 1 # After waiting, attempt an update once more, if fails, return error code @@ -153,7 +150,7 @@ do done fi break - elif [[ $update_avail == "false" ]]; then + elif [[ $app_update_avail == "false" && $cont_update_avail == "false" ]]; then break else sleep 3 @@ -224,7 +221,13 @@ if [[ $rollback == "true" || "$startstatus" == "STOPPED" ]]; then fi elif [[ "$SECONDS" -ge "$timeout" ]]; then if [[ $rollback == "true" ]]; then - if [[ "$failed" != "true" ]]; then + if [[ $old_full_ver == "$new_full_ver" ]]; then + echo_array+=("Error: Run Time($SECONDS) for $app_name has exceeded Timeout($timeout)") + echo_array+=("This is the result of a container image update..") + echo_array+=("Reverting is not possible, Abandoning") + echo_array + return 1 + elif [[ "$failed" != "true" ]]; then echo_array+=("Error: Run Time($SECONDS) for $app_name has exceeded Timeout($timeout)") echo_array+=("If this is a slow starting application, set a higher timeout with -t") echo_array+=("If this applicaion is always DEPLOYING, you can disable all probes under the Healthcheck Probes Liveness section in the edit configuration") @@ -283,10 +286,10 @@ export -f after_update_actions rollback_app(){ count=0 -update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}') -while [[ $update_avail == "false" ]] +app_update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}') +while [[ $app_update_avail == "false" ]] do - update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}') + app_update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}') if [[ $count -gt 2 ]]; then # If failed to rollback app 3 times, return failure to parent shell return 1 elif ! cli -c "app chart_release rollback release_name=\"$app_name\" rollback_options={\"item_version\": \"$rollback_version\"}" &> /dev/null ; then @@ -308,10 +311,11 @@ for i in "${echo_array[@]}" do echo -e "$i" done - +final_check } export -f echo_array + final_check(){ [[ ! -e finished ]] && touch finished echo "$app_name,finished" >> finished From 2bc4ba3d6226a19fc5d5346828b9b72a873714a2 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Wed, 24 Aug 2022 17:05:16 -0600 Subject: [PATCH 4/4] use regex rather than 2 variables to check update --- functions/update_apps.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/functions/update_apps.sh b/functions/update_apps.sh index 282e5c03..61d670a6 100644 --- a/functions/update_apps.sh +++ b/functions/update_apps.sh @@ -132,13 +132,12 @@ update_app(){ current_loop=0 while true do - app_update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}') - cont_update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $6}') - if [[ $app_update_avail == "true" || $cont_update_avail == "true" ]]; then + update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $3","$6}') + if [[ $update_avail =~ "true" ]]; then if ! cli -c 'app chart_release upgrade release_name=''"'"$app_name"'"' &> /dev/null ; then before_loop=$(head -n 1 all_app_status) current_loop=0 - until [[ "$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}')" != "$app_update_avail" || "$(grep "^$app_name," all_app_status | awk -F ',' '{print $6}')" != "$cont_update_avail" ]] # Wait for a specific change to app status, or 3 refreshes of the file to go by. + until [[ "$(grep "^$app_name," all_app_status | awk -F ',' '{print $3","$6}')" != "$update_avail" ]] # Wait for a specific change to app status, or 3 refreshes of the file to go by. do if [[ $current_loop -gt 2 ]]; then cli -c 'app chart_release upgrade release_name=''"'"$app_name"'"' &> /dev/null || return 1 # After waiting, attempt an update once more, if fails, return error code @@ -150,7 +149,7 @@ do done fi break - elif [[ $app_update_avail == "false" && $cont_update_avail == "false" ]]; then + elif [[ ! $update_avail =~ "true" ]]; then break else sleep 3