Report each teardown and setup step from what it did, not from whether it was attempted
This commit is contained in:
@@ -532,6 +532,10 @@ gather_partner_fallback_containers() {
|
||||
|
||||
# Start this server's own parked containers after partnership ends.
|
||||
start_own_stack() {
|
||||
# Returns non-zero if any container failed. It used to return whatever the loop's last
|
||||
# docker start happened to produce, so a caller checking it learned nothing — and the
|
||||
# offboard summary just printed "Step 6 — Own stack: started" either way.
|
||||
local _rc=0
|
||||
echo ""
|
||||
echo "━━━ $ICON_START Restart Own Stack ━━━"
|
||||
if [[ ${#PARTNERSHIP_OWN_CONTAINERS[@]} -eq 0 ]]; then
|
||||
@@ -548,14 +552,20 @@ start_own_stack() {
|
||||
echo "$container started ✅"
|
||||
else
|
||||
warn "$container failed to start — check manually"
|
||||
_rc=1
|
||||
fi
|
||||
done
|
||||
return "$_rc"
|
||||
}
|
||||
|
||||
# Remove partnership containers on this server + their appdata bind-mount paths.
|
||||
# Appdata paths collected via docker inspect BEFORE removal — inspect fails on removed containers.
|
||||
# Safety gate: only paths matching /mnt/*/appdata* are deleted.
|
||||
cleanup_partner_containers() {
|
||||
# Returns non-zero if any container or appdata path could not be removed. Previously the
|
||||
# exit status was whatever the trailing while-loop produced, so "Step 5 — Local cleanup: ✅"
|
||||
# was printed over a container that failed to remove.
|
||||
local _rc=0
|
||||
declare -a containers=()
|
||||
gather_partner_fallback_containers containers
|
||||
|
||||
@@ -586,8 +596,12 @@ cleanup_partner_containers() {
|
||||
if timeout "${DOCKER_TIMEOUT:-30}" docker inspect "$container" >/dev/null 2>&1; then
|
||||
timeout "${DOCKER_TIMEOUT:-30}" docker stop "$container" >/dev/null 2>&1 || true
|
||||
_PM_TRAP_STOPPED+=("$container")
|
||||
timeout "${DOCKER_TIMEOUT:-30}" docker rm "$container" >/dev/null 2>&1 && \
|
||||
echo "$container removed ✅" || warn "$container rm failed"
|
||||
if timeout "${DOCKER_TIMEOUT:-30}" docker rm "$container" >/dev/null 2>&1; then
|
||||
echo "$container removed ✅"
|
||||
else
|
||||
warn "$container rm failed"
|
||||
_rc=1
|
||||
fi
|
||||
else
|
||||
log "$container not found — skipping"
|
||||
fi
|
||||
@@ -600,8 +614,14 @@ cleanup_partner_containers() {
|
||||
warn " DRY RUN — would rm -rf $path"
|
||||
continue
|
||||
fi
|
||||
rm -rf "$path" && echo " Appdata removed: $path ✅" || warn " Failed to remove: $path"
|
||||
if rm -rf "$path"; then
|
||||
echo " Appdata removed: $path ✅"
|
||||
else
|
||||
warn " Failed to remove: $path"
|
||||
_rc=1
|
||||
fi
|
||||
done <<< "$all_appdata_paths"
|
||||
return "$_rc"
|
||||
}
|
||||
|
||||
# SSH to mirror — remove all containers named *-${OWNER_SHORT} (owner's deployed containers)
|
||||
@@ -609,6 +629,10 @@ cleanup_partner_containers() {
|
||||
# Appdata paths collected via SSH docker inspect before removal, then deleted via SSH.
|
||||
# Safety gate: only paths matching /mnt/*/appdata* are deleted on the remote.
|
||||
cleanup_owner_containers_on_mirror() {
|
||||
# Returns non-zero if any remote removal failed, so the caller can report Step 7 honestly
|
||||
# rather than from MIRROR_REACHABLE — which only says the mirror answered, not that the
|
||||
# containers on it are gone.
|
||||
local _rc=0
|
||||
local mirror_ip="$1"
|
||||
local owner_short
|
||||
owner_short=$(derive_short_name "$OWNER")
|
||||
@@ -639,24 +663,31 @@ cleanup_owner_containers_on_mirror() {
|
||||
"docker inspect --format '{{range .HostConfig.Binds}}{{println .}}{{end}}' '$container' 2>/dev/null \
|
||||
| awk -F: '{print \$1}' | grep '^/mnt/.*/appdata'" 2>/dev/null)
|
||||
|
||||
timeout "$SSH_TIMEOUT" ssh -i "$SSH_KEY" \
|
||||
if timeout "$SSH_TIMEOUT" ssh -i "$SSH_KEY" \
|
||||
-o ConnectTimeout="$SSH_TIMEOUT" -o BatchMode=yes root@"$mirror_ip" \
|
||||
"docker stop '$container' >/dev/null 2>&1
|
||||
docker rm '$container' >/dev/null 2>&1 && echo removed" 2>/dev/null | \
|
||||
grep -q removed && \
|
||||
echo "$container removed from $MIRROR ✅" || \
|
||||
grep -q removed; then
|
||||
echo "$container removed from $MIRROR ✅"
|
||||
else
|
||||
warn "Failed to remove $container from $MIRROR"
|
||||
_rc=1
|
||||
fi
|
||||
|
||||
# Delete appdata on remote after container removal
|
||||
while IFS= read -r path; do
|
||||
[[ -z "$path" ]] && continue
|
||||
timeout "$SSH_TIMEOUT" ssh -i "$SSH_KEY" \
|
||||
if timeout "$SSH_TIMEOUT" ssh -i "$SSH_KEY" \
|
||||
-o ConnectTimeout="$SSH_TIMEOUT" -o BatchMode=yes root@"$mirror_ip" \
|
||||
"rm -rf '$path' && echo removed" 2>/dev/null | grep -q removed && \
|
||||
echo " Appdata removed on $MIRROR: $path ✅" || \
|
||||
"rm -rf '$path' && echo removed" 2>/dev/null | grep -q removed; then
|
||||
echo " Appdata removed on $MIRROR: $path ✅"
|
||||
else
|
||||
warn " Failed to remove appdata on $MIRROR: $path"
|
||||
_rc=1
|
||||
fi
|
||||
done <<< "$appdata_paths"
|
||||
done <<< "$container_list"
|
||||
return "$_rc"
|
||||
}
|
||||
|
||||
# SSH to mirror — start mirror's own parked containers.
|
||||
@@ -678,18 +709,23 @@ start_mirror_own_stack() {
|
||||
fi
|
||||
|
||||
log "Restarting own stack on $MIRROR: ${mirror_own[*]}"
|
||||
local _rc=0
|
||||
for container in "${mirror_own[@]}"; do
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
warn "DRY RUN — would start $container on $MIRROR"
|
||||
continue
|
||||
fi
|
||||
timeout "$SSH_TIMEOUT" ssh -i "$SSH_KEY" \
|
||||
if timeout "$SSH_TIMEOUT" ssh -i "$SSH_KEY" \
|
||||
-o ConnectTimeout="$SSH_TIMEOUT" -o BatchMode=yes root@"$mirror_ip" \
|
||||
"docker start '$container' >/dev/null 2>&1 && echo started" 2>/dev/null | \
|
||||
grep -q started && \
|
||||
echo "$container started on $MIRROR ✅" || \
|
||||
grep -q started; then
|
||||
echo "$container started on $MIRROR ✅"
|
||||
else
|
||||
warn "$container failed to start on $MIRROR — check manually"
|
||||
_rc=1
|
||||
fi
|
||||
done
|
||||
return "$_rc"
|
||||
}
|
||||
|
||||
# Create the mirror's Emby admin account on the owner's deployed Emby.
|
||||
|
||||
Reference in New Issue
Block a user