nomad_smartrestart: add pretty colours
This commit is contained in:
parent
886470f8a2
commit
fd4074798e
1 changed files with 57 additions and 19 deletions
|
@ -1,29 +1,52 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e;
|
set -e;
|
||||||
|
|
||||||
|
cd "$(dirname "$(readlink -f "$0")")" || { echo "Error: Failed to cd to script directory" >&2; exit 1; };
|
||||||
|
|
||||||
|
imagename="${1}"
|
||||||
|
|
||||||
jobname="${1}";
|
jobname="${1}";
|
||||||
taskname="${2}";
|
taskname="${2}";
|
||||||
|
|
||||||
|
if [[ -z "${NO_COLOR}" ]]; then
|
||||||
|
RS="\033[0m" # reset
|
||||||
|
HC="\033[1m" # hicolor
|
||||||
|
|
||||||
|
FRED="\033[31m" # foreground red
|
||||||
|
FGRN="\033[32m" # foreground green
|
||||||
|
FYEL="\033[33m" # foreground yellow
|
||||||
|
FBLE="\033[34m" # foreground blue
|
||||||
|
fi
|
||||||
|
|
||||||
help() {
|
help() {
|
||||||
echo "nomad_smartrestart, v0.1
|
echo "nomad_smartrestart, v0.1
|
||||||
By Starbeamrainbowlabs
|
By Starbeamrainbowlabs
|
||||||
|
|
||||||
USAGE
|
${FBLE}${HC}USAGE${RS}
|
||||||
path/to/nomad_smartrestart.sh {JOB_NAME} {TASK_NAME}
|
path/to/nomad_smartrestart.sh {IMAGE_NAME}
|
||||||
|
|
||||||
ENVIRONMENT VARIABLES
|
${FBLE}${HC}ENVIRONMENT VARIABLES${RS}
|
||||||
URL_NOMAD The URL of the nomad server to talk to (using the Consul domain instead of a direct IP is recommended)"
|
${FYEL}URL_NOMAD${RS} The URL of the nomad server to talk to (using the Consul domain instead of a direct IP is recommended)"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ -z "${jobname}" ]]; then
|
log_msg() {
|
||||||
echo "Error: No jobname specified." >&2;
|
echo "${HC}>>> nomad_smartrestart: ${RS}$*" >&2;
|
||||||
|
}
|
||||||
|
log_error() {
|
||||||
|
echo "${HC}>>> nomad_smartrestart: ${FRED}$*${RS}";
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ -z "${imagename}" ]]; then
|
||||||
|
log_error "Error: No image name specified." >&2;
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
if [[ -z "${taskname}" ]]; then
|
|
||||||
echo "Error: No taskname specified." >&2;
|
if [[ ! -f "./images/${imagename}/nomad.txt" ]]; then
|
||||||
exit 1;
|
log_msg "No nomad.txt present for ${HC}${FGRN}${imagename}${RS}, nothing to do";
|
||||||
|
exit 0;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
URL_NOMAD="${URL_NOMAD:-http://nomad.service.mooncarrot.space:4646}";
|
URL_NOMAD="${URL_NOMAD:-http://nomad.service.mooncarrot.space:4646}";
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -54,14 +77,29 @@ nomad_alloc_restart() {
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
|
||||||
|
count_tasks=0;
|
||||||
count_restarted=0;
|
count_restarted=0;
|
||||||
|
while read -r jobname taskname; do
|
||||||
|
if [[ -z "${jobname}" ]]; then
|
||||||
|
log_error "Error: No jobname specified." >&2;
|
||||||
|
continue;
|
||||||
|
fi
|
||||||
|
if [[ -z "${taskname}" ]]; then
|
||||||
|
log_error "Error: No taskname specified." >&2;
|
||||||
|
continue;
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_msg "Checking ${FYEL}${HC}${jobname}:${taskname}${RS}";
|
||||||
|
|
||||||
while read -r alloc_id jobname taskname; do
|
while read -r alloc_id jobname taskname; do
|
||||||
alloc_id_short="$(echo "${alloc_id}" | head -c7)";
|
alloc_id_short="$(echo "${alloc_id}" | head -c7)";
|
||||||
|
log_msg "Restarting allocation ${HC}${FBLE}${alloc_id_short}${RC} in-place";
|
||||||
log_msg "[nomad_smartrestart] Restarting allocation ${alloc_id_short} in-place for ${jobname}:${taskname}";
|
|
||||||
|
|
||||||
nomad_alloc_restart "${alloc_id}";
|
nomad_alloc_restart "${alloc_id}";
|
||||||
count_restarted="$((count_restarted+1))"
|
count_restarted="$((count_restarted+1))";
|
||||||
done < <(nomad_allocs_find "${jobname}" "${taskname}");
|
done < <(nomad_allocs_find "${jobname}" "${taskname}");
|
||||||
|
count_tasks="$((count_tasks+1))";
|
||||||
|
done
|
||||||
|
|
||||||
echo "[nomad_smartrestart] Restarted ${count_restarted} allocations in-place";
|
log_msg "Restarted ${HC}${count_restarted}${RS} allocations for ${HC}${count_tasks}${RS} tasks in-place";
|
||||||
|
|
Loading…
Reference in a new issue