refactor: unify stack management output
This commit is contained in:
1 parent
c76b2dfb9d
commit
50d9fc69ad
1 file changed
+36
-17
@@ -9,6 +9,11 @@ CONFIG_FILE="${STACKS_CONFIG:-$STACKS_DIR/manage.conf}"
|
|||||||
LOCK_FILE="${STACKS_LOCK_FILE:-/run/lock/stacks-manage.lock}"
|
LOCK_FILE="${STACKS_LOCK_FILE:-/run/lock/stacks-manage.lock}"
|
||||||
|
|
||||||
DEFAULT_MAX_PARALLEL=2
|
DEFAULT_MAX_PARALLEL=2
|
||||||
|
OUTPUT_IS_TTY=0
|
||||||
|
|
||||||
|
if [[ -t 1 && -z "${NO_COLOR+x}" ]]; then
|
||||||
|
OUTPUT_IS_TTY=1
|
||||||
|
fi
|
||||||
|
|
||||||
CONFIG_GROUP_NAMES=()
|
CONFIG_GROUP_NAMES=()
|
||||||
CONFIG_GROUP_LIMITS=()
|
CONFIG_GROUP_LIMITS=()
|
||||||
@@ -26,6 +31,7 @@ UNASSIGNED_STACKS=()
|
|||||||
RUN_SUCCESS=0
|
RUN_SUCCESS=0
|
||||||
RUN_FAILED=0
|
RUN_FAILED=0
|
||||||
RUN_FAILED_STACKS=()
|
RUN_FAILED_STACKS=()
|
||||||
|
RUN_SKIPPED_GROUPS=()
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
echo "ERROR: $*" >&2
|
echo "ERROR: $*" >&2
|
||||||
@@ -297,7 +303,7 @@ run_stack_prefixed() {
|
|||||||
local action="$2"
|
local action="$2"
|
||||||
local line status
|
local line status
|
||||||
|
|
||||||
STACKS_FORCE_ANSI=1 run_stack "$stack" "$action" 0 2>&1 |
|
STACKS_FORCE_ANSI="$OUTPUT_IS_TTY" run_stack "$stack" "$action" 0 2>&1 |
|
||||||
while IFS= read -r line || [[ -n "$line" ]]; do
|
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||||
[[ -n "$line" ]] || continue
|
[[ -n "$line" ]] || continue
|
||||||
printf '[%s] %s\n' "$stack" "$line"
|
printf '[%s] %s\n' "$stack" "$line"
|
||||||
@@ -313,7 +319,7 @@ run_group() {
|
|||||||
local group_name="${GROUP_NAMES[group_index]}"
|
local group_name="${GROUP_NAMES[group_index]}"
|
||||||
local limit="${GROUP_LIMITS[group_index]}"
|
local limit="${GROUP_LIMITS[group_index]}"
|
||||||
local semaphore_dir semaphore_fifo semaphore_fd
|
local semaphore_dir semaphore_fifo semaphore_fd
|
||||||
local stack pid i status
|
local stack pid i status details
|
||||||
local failed=0
|
local failed=0
|
||||||
local -a stacks=() pids=() pid_stacks=()
|
local -a stacks=() pids=() pid_stacks=()
|
||||||
|
|
||||||
@@ -324,8 +330,16 @@ run_group() {
|
|||||||
limit="${#stacks[@]}"
|
limit="${#stacks[@]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ((${#stacks[@]} == 1)); then
|
||||||
|
details="1 stack"
|
||||||
|
elif ((limit == ${#stacks[@]})); then
|
||||||
|
details="${#stacks[@]} stacks in parallel"
|
||||||
|
else
|
||||||
|
details="${#stacks[@]} stacks, max $limit in parallel"
|
||||||
|
fi
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "==> Group $group_name: $action (${#stacks[@]} stacks, parallel=$limit)"
|
echo "==> Group $group_name: $action ($details)"
|
||||||
|
|
||||||
semaphore_dir="$(mktemp -d "${TMPDIR:-/tmp}/stacks-manage.XXXXXX")" ||
|
semaphore_dir="$(mktemp -d "${TMPDIR:-/tmp}/stacks-manage.XXXXXX")" ||
|
||||||
die "cannot create semaphore directory"
|
die "cannot create semaphore directory"
|
||||||
@@ -373,33 +387,33 @@ run_group() {
|
|||||||
|
|
||||||
print_run_summary() {
|
print_run_summary() {
|
||||||
echo
|
echo
|
||||||
echo "Succeeded: $RUN_SUCCESS"
|
echo "Result: $RUN_SUCCESS succeeded, $RUN_FAILED failed"
|
||||||
echo "Failed: $RUN_FAILED"
|
|
||||||
|
|
||||||
if ((${#RUN_FAILED_STACKS[@]} > 0)); then
|
if ((${#RUN_FAILED_STACKS[@]} > 0)); then
|
||||||
echo "Failures: ${RUN_FAILED_STACKS[*]}"
|
echo "Failed stacks: ${RUN_FAILED_STACKS[*]}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ((${#RUN_SKIPPED_GROUPS[@]} > 0)); then
|
||||||
|
echo "Skipped groups: ${RUN_SKIPPED_GROUPS[*]}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
print_skipped_groups() {
|
collect_skipped_groups() {
|
||||||
local failed_index="$1"
|
local failed_index="$1"
|
||||||
local direction="$2"
|
local direction="$2"
|
||||||
local i
|
local i
|
||||||
local -a skipped=()
|
|
||||||
|
RUN_SKIPPED_GROUPS=()
|
||||||
|
|
||||||
if [[ "$direction" == "reverse" ]]; then
|
if [[ "$direction" == "reverse" ]]; then
|
||||||
for ((i = failed_index - 1; i >= 0; i--)); do
|
for ((i = failed_index - 1; i >= 0; i--)); do
|
||||||
skipped+=("${GROUP_NAMES[i]}")
|
RUN_SKIPPED_GROUPS+=("${GROUP_NAMES[i]}")
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
for ((i = failed_index + 1; i < ${#GROUP_NAMES[@]}; i++)); do
|
for ((i = failed_index + 1; i < ${#GROUP_NAMES[@]}; i++)); do
|
||||||
skipped+=("${GROUP_NAMES[i]}")
|
RUN_SKIPPED_GROUPS+=("${GROUP_NAMES[i]}")
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ((${#skipped[@]} > 0)); then
|
|
||||||
echo "Skipped groups after failure: ${skipped[*]}" >&2
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run_all_grouped() {
|
run_all_grouped() {
|
||||||
@@ -410,13 +424,14 @@ run_all_grouped() {
|
|||||||
RUN_SUCCESS=0
|
RUN_SUCCESS=0
|
||||||
RUN_FAILED=0
|
RUN_FAILED=0
|
||||||
RUN_FAILED_STACKS=()
|
RUN_FAILED_STACKS=()
|
||||||
|
RUN_SKIPPED_GROUPS=()
|
||||||
warn_unassigned
|
warn_unassigned
|
||||||
|
|
||||||
if [[ "$action" == "stop" || "$action" == "down" ]]; then
|
if [[ "$action" == "stop" || "$action" == "down" ]]; then
|
||||||
direction="reverse"
|
direction="reverse"
|
||||||
for ((i = ${#GROUP_NAMES[@]} - 1; i >= 0; i--)); do
|
for ((i = ${#GROUP_NAMES[@]} - 1; i >= 0; i--)); do
|
||||||
if ! run_group "$i" "$action"; then
|
if ! run_group "$i" "$action"; then
|
||||||
print_skipped_groups "$i" "$direction"
|
collect_skipped_groups "$i" "$direction"
|
||||||
print_run_summary
|
print_run_summary
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -424,7 +439,7 @@ run_all_grouped() {
|
|||||||
else
|
else
|
||||||
for ((i = 0; i < ${#GROUP_NAMES[@]}; i++)); do
|
for ((i = 0; i < ${#GROUP_NAMES[@]}; i++)); do
|
||||||
if ! run_group "$i" "$action"; then
|
if ! run_group "$i" "$action"; then
|
||||||
print_skipped_groups "$i" "$direction"
|
collect_skipped_groups "$i" "$direction"
|
||||||
print_run_summary
|
print_run_summary
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -441,6 +456,7 @@ run_all_sequential() {
|
|||||||
RUN_SUCCESS=0
|
RUN_SUCCESS=0
|
||||||
RUN_FAILED=0
|
RUN_FAILED=0
|
||||||
RUN_FAILED_STACKS=()
|
RUN_FAILED_STACKS=()
|
||||||
|
RUN_SKIPPED_GROUPS=()
|
||||||
warn_unassigned
|
warn_unassigned
|
||||||
|
|
||||||
for stack in "${MANAGED_STACKS[@]}"; do
|
for stack in "${MANAGED_STACKS[@]}"; do
|
||||||
@@ -452,7 +468,10 @@ run_all_sequential() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
print_run_summary
|
if ((RUN_FAILED > 0)); then
|
||||||
|
echo
|
||||||
|
echo "Failed stacks: ${RUN_FAILED_STACKS[*]}" >&2
|
||||||
|
fi
|
||||||
((RUN_FAILED == 0))
|
((RUN_FAILED == 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user