Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
update start and stop and update help
Browse files Browse the repository at this point in the history
  • Loading branch information
Heavybullets8 committed Aug 17, 2023
1 parent a137747 commit 6851e0a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 43 deletions.
17 changes: 8 additions & 9 deletions functions/app/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@
app_help() {
echo -e "${bold}App Handler${reset}"
echo -e "${bold}-----------${reset}"
echo -e "${blue}heavyscript app [Option] [app_name]${reset}"
echo -e "${blue}heavyscript app [Option] [app_name(s)]${reset}"
echo
echo -e "${bold}Description${reset}"
echo -e "${bold}-----------${reset}"
echo -e "Start, stop, restart and delete applications"
echo -e "Start, stop, restart, and delete applications."
echo
echo -e "${bold}Options${reset}"
echo -e "${bold}-------${reset}"
echo -e "${blue}-s${reset}, ${blue}--start${reset} [app_name]"
echo -e " Start an application. If no app_name is provided, the user will be prompted to select one."
echo -e "${blue}-x${reset}, ${blue}--stop${reset} [app_name]"
echo -e " Stop an application. If no app_name is provided, the user will be prompted to select one."
echo -e "${blue}-r${reset}, ${blue}--restart${reset} [app_name]"
echo -e " Restart an application. If no app_name is provided, the user will be prompted to select one."
echo -e "${blue}-s${reset}, ${blue}--start${reset} [app_name(s)]"
echo -e " Start applications. You can specify multiple app names or use the keyword 'ALL' to start all applications. If no app_name is provided, the user will be prompted to select one."
echo -e "${blue}-x${reset}, ${blue}--stop${reset} [app_name(s)]"
echo -e " Stop applications. You can specify multiple app names or use the keyword 'ALL' to stop all applications. If no app_name is provided, the user will be prompted to select one."
echo -e "${blue}-r${reset}, ${blue}--restart${reset} [app_name(s)]"
echo -e " Restart applications. You can specify multiple app names or use the keyword 'ALL' to restart all applications. If no app_name is provided, the user will be prompted to select one."
echo -e "${blue}-d${reset}, ${blue}--delete${reset} [app_name]"
echo -e " Delete an application. If no app_name is provided, the user will be prompted to select one."
echo -e "${blue}-h${reset}, ${blue}--help${reset}"
echo -e " Display this help message."
echo
}


41 changes: 25 additions & 16 deletions functions/app/start_app.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
#!/bin/bash

# shellcheck disable=SC2120
start_app_prompt() {
local app_names=("$@") # Get all arguments as an array

start_app_prompt(){
while true; do
# Prompt user to select an application if one was not passed to the function
if [[ -z $1 ]]; then
prompt_app_selection "STOPPED" "start"
app_name=$(echo "${apps[app_index-1]}" | awk -F ',' '{print $1}')
clear -x
title
else
app_name="$1"
fi
# If the first argument is "ALL", populate the app_names array with all apps
if [[ ${app_names[0]} == "ALL" ]]; then
mapfile -t app_names < <(cli -m csv -c 'app chart_release query name' | tail -n +2 | sort | tr -d " \t\r" | awk 'NF')
fi

# If no arguments are provided, prompt for app selection
if [[ ${#app_names[@]} -eq 0 ]]; then
prompt_app_selection "STOPPED" "start"
app_name=$(echo "${apps[app_index-1]}" | awk -F ',' '{print $1}')
app_names=("$app_name")
fi

for app_name in "${app_names[@]}"; do
# Query chosen replica count for the application
replica_count=$(pull_replicas "$app_name")

Expand Down Expand Up @@ -43,15 +47,20 @@ start_app_prompt(){
else
echo -e "${red}Failed to start ${blue}$app_name${reset}"
fi
done

if [[ -n $1 ]]; then
break
fi
# If app names were provided as arguments, we're done
if [[ ${#app_names[@]} -gt 0 ]]; then
return
fi

# If not, offer the user a chance to start another app
while true; do
read -rt 120 -p "Would you like to start another application? (y/n): " choice || { echo -e "\n${red}Failed to make a selection in time${reset}" ; exit; }
case "$(echo "$choice" | tr '[:upper:]' '[:lower:]')" in
"yes"|"y")
continue
start_app_prompt
break
;;
"no"|"n"|"")
break
Expand All @@ -60,4 +69,4 @@ start_app_prompt(){
echo "Invalid choice, please enter 'y' or 'n'"
esac
done
}
}
45 changes: 27 additions & 18 deletions functions/app/stop_app.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
#!/bin/bash


# shellcheck disable=SC2120
stop_app_prompt(){
while true; do
# Prompt user to select an application if one was not passed to the function
if [[ -z $1 ]]; then
prompt_app_selection "ACTIVE" "stop"
app_name=$(echo "${apps[app_index-1]}" | awk -F ',' '{print $1}')
clear -x
title
else
app_name="$1"
fi

echo -e "Stopping ${blue}$app_name${reset}..."
local app_names=("$@") # Get all arguments as an array

# If the first argument is "ALL", populate the app_names array with all apps
if [[ ${app_names[0]} == "ALL" ]]; then
mapfile -t app_names < <(cli -m csv -c 'app chart_release query name' | tail -n +2 | sort | tr -d " \t\r" | awk 'NF')
fi

# If no arguments are provided, prompt for app selection
if [[ ${#app_names[@]} -eq 0 ]]; then
prompt_app_selection "ACTIVE" "stop"
app_name=$(echo "${apps[app_index-1]}" | awk -F ',' '{print $1}')
app_names=("$app_name")
fi

for app_name in "${app_names[@]}"; do
echo -e "Stopping ${blue}$app_name${reset}..."

stop_app "normal" "$app_name" "${timeout:-50}"
result=$(handle_stop_code "$?")
if [[ $? -eq 1 ]]; then
Expand All @@ -23,15 +27,20 @@ stop_app_prompt(){
else
echo -e "${green}${result}${reset}"
fi
done

if [[ -n $1 ]]; then
break
fi
# If app names were provided as arguments, we're done
if [[ ${#app_names[@]} -gt 0 ]]; then
return
fi

# If not, offer the user a chance to stop another app
while true; do
read -rt 120 -p "Would you like to stop another application? (y/n): " choice || { echo -e "\n${red}Failed to make a selection in time${reset}" ; exit; }
case "$(echo "$choice" | tr '[:upper:]' '[:lower:]')" in
"yes"|"y")
continue
stop_app_prompt
break
;;
"no"|"n"|"")
break
Expand All @@ -40,4 +49,4 @@ stop_app_prompt(){
echo "Invalid choice, please enter 'y' or 'n'"
esac
done
}
}

0 comments on commit 6851e0a

Please sign in to comment.