echo"-m | Initiates mounting feature, choose between unmounting and mounting PVC data"
echo"-r | Opens a menu to restore a heavy_script backup that was taken on you ix-applications pool"
echo"-b | Back-up your ix-applications dataset, specify a number after -b"
echo"-i | Add application to ignore list, one by one, see example below."
echo"-R | Roll-back applications if they fail to update"
echo"-S | Shutdown applications prior to updating"
echo"-v | verbose output"
echo"-t | Set a custom timeout in seconds when checking if either an App or Mountpoint correctly Started, Stopped or (un)Mounted. Defaults to 500 seconds"
echo"-s | sync catalog"
echo"-S | Stops App before update with -u or -U and restarts afterwards"
echo"-U | Update all applications, ignores versions"
echo"-u | Update all applications, does not update Major releases"
list_backups=$(cli -c 'app kubernetes list_backups'| grep "HeavyScript_"| sort -rV | tr -d " \t\r"| awk -F '|''{print NR-1, $2}'| column -t)&&echo"$list_backups"&&read -p "Please type a number: " selection &&restore_point=$(echo"$list_backups"| grep ^"$selection"| awk '{print $2}')&&echo -e "\nThis is NOT guranteed to work\nThis is ONLY supposed to be used as a LAST RESORT\nConsider rolling back your applications instead if possible.\n\nYou have chosen to restore $restore_point\nWould you like to continue?"&&echo -e "1 Yes\n2 No"&&read -p "Please type a number: " yesno ||{echo"FAILED"; exit;}
if[[$yesno=="1"]];then
echo -e "\nStarting Backup, this will take a LONG time."&& cli -c 'app kubernetes restore_backup backup_name=''"'"$restore_point"'"'||echo"Restore FAILED"
elif[[$yesno=="2"]];then
echo"You've chosen NO, killing script. Good luck."
else
echo"Invalid Selection"
fi
}
export -f restore
mount(){
echo -e "1 Mount\n2 Unmount All"&&read -p "Please type a number: " selection
echo -e "Waiting $((timeout-SECONDS)) more seconds for $app to be STOPPED"&& sleep 10
done
data_name=$(echo"$pvc"| awk '{print $3}')
mount=$(echo"$pvc"| awk '{print $4}')
volume_name=$(echo"$pvc"| awk '{print $4}')
full_path=$(zfs list | grep $volume_name| awk '{print $1}')
echo -e "\nMounting\n"$full_path"\nTo\n/mnt/temporary/$data_name"&& zfs setmountpoint=/temporary/"$data_name""$full_path"&&echo -e "Mounted\n\nUnmount with the following command\nzfs set mountpoint=legacy "$full_path" && rmdir /mnt/temporary/"$data_name"\nOr use the Unmount All option\n"
exit
elif[[$selection=="2"]];then
mapfile -t unmount_array < <(basename -a /mnt/temporary/* | sed "s/*//")
[[ -z $unmount_array]]&&echo"Theres nothing to unmount"&&exit
for i in "${unmount_array[@]}"
do
main=$(k3s kubectl get pvc -A | grep "$i"| awk '{print $1, $2, $4}')
echo -e "Error: Run Time($SECONDS) for $app_name has exceeded Timeout($timeout)\nIf this is a slow starting application, set a higher timeout with -t\nIf this applicaion is always DEPLOYING, you can disable all probes under the Healthcheck Probes Liveness section in the edit configuration\nReverting update..."
[["$startstatus"=="STOPPED"]]&&failed="true"&& after_update_actions &&unset failed #run back after_update_actions function if the app was stopped prior to update
echo -e "Error: Run Time($SECONDS) for $app_name has exceeded Timeout($timeout)\nThe application failed to be ACTIVE even after a rollback,\nManual intervention is required\nAbandoning"
break
elif[["$status"=="STOPPED"]];then
[["$count" -le 1]]&&echo"Verifying Stopped.."&& sleep 15&&continue#if reports stopped on FIRST time through loop, double check
[["$count" -ge 2]]&&echo"Error: Application appears to be stuck in stopped state"&&break#if reports stopped any time after the first loop, assume its broken.
elif[["$status"=="ACTIVE"]];then
[["$count" -le 1]]&&echo"Verifying Active.."&& sleep 15&&continue#if reports active on FIRST time through loop, double check
[["$count" -ge 2]]&&echo"Active"&&break#if reports active any time after the first loop, assume actually active.
else
[["$verbose"=="true"]]&&echo"Waiting $((timeout-SECONDS)) more seconds for $app_name to be ACTIVE"
[["$count" -ge 2]]&&status=$(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,status'| grep ""$app_name","| awk -F ',''{print $2}')#Skip first status check, due to the one directly above it.