nomad_smartrestart: tidy up

This commit is contained in:
Starbeamrainbowlabs 2020-09-05 20:55:02 +01:00
parent c76a96e395
commit 2964c006e7
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -3,10 +3,7 @@ set -e;
cd "$(dirname "$(readlink -f "$0")")" || { echo "Error: Failed to cd to script directory" >&2; exit 1; };
imagename="${1}"
jobname="${1}";
taskname="${2}";
imagename="${1}";
if [[ -z "${NO_COLOR}" ]]; then
RS="\033[0m" # reset
@ -19,7 +16,7 @@ if [[ -z "${NO_COLOR}" ]]; then
fi
help() {
echo -e "nomad_smartrestart, v0.1
echo -e "${FGRN}${HC}nomad_smartrestart${RS}, ${HC}v0.1${RS}
By Starbeamrainbowlabs
${FBLE}${HC}USAGE${RS}
@ -42,7 +39,9 @@ if [[ -z "${imagename}" ]]; then
exit 1;
fi
if [[ ! -f "./images/${imagename}/nomad.txt" ]]; then
loc_nomad_txt="./images/${imagename}/nomad.txt";
if [[ ! -f "${loc_nomad_txt}" ]]; then
log_msg "No nomad.txt present for ${HC}${FGRN}${imagename}${RS}, nothing to do";
help;
exit 0;
@ -74,6 +73,7 @@ nomad_alloc_restart() {
local alloc_id="${1}"
curl -sS "${URL_NOMAD}/v1/client/allocation/${alloc_id}/restart";
echo
}
@ -96,12 +96,12 @@ while read -r jobname taskname; do
while read -r alloc_id jobname taskname; do
alloc_id_short="$(echo "${alloc_id}" | head -c7)";
log_msg "Restarting allocation ${HC}${FBLE}${alloc_id_short}${RC} in-place";
log_msg "Restarting allocation ${HC}${FBLE}${alloc_id_short}${RS} in-place";
nomad_alloc_restart "${alloc_id}";
count_restarted="$((count_restarted+1))";
done < <(nomad_allocs_find "${jobname}" "${taskname}");
count_tasks="$((count_tasks+1))";
done
done <"${loc_nomad_txt}"
log_msg "Restarted ${HC}${count_restarted}${RS} allocations for ${HC}${count_tasks}${RS} tasks in-place";