deploy: apply helper reboots only when the rollback itself failed

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KqhjP7nud5gdBg25zCiRk9
This commit is contained in:
2026-09-23 18:46:16 -04:00
co-authored by Claude Sonnet 5
parent d46fd5a1e4
commit ca7d22384b
2 changed files with 15 additions and 4 deletions
+4 -1
View File
@@ -345,10 +345,13 @@ restore() { # restore <reason>: put the pre-run netplan back, re-check connecti
if [ "\$rb" = ok ] && [ "\$c" = ok ]; then
echo "apply-network ROLLED BACK (restored, connectivity ok)"
status rolled-back "\$1"
elif [ "\$rb" = ok ]; then
echo "apply-network ROLLED BACK (restored, but no connectivity - check the uplink/cable)"
status rolled-back restored-no-connectivity
else
echo "apply-network ROLLBACK FAILED: \$rb / connectivity \$c"
status rollback-failed "\$1; \$rb / connectivity \$c"
[ "\$c" = ok ] || { echo "no connectivity after rollback - rebooting"; systemctl reboot; }
[ "\$c" = ok ] || { echo "rollback failed and no connectivity - rebooting (boot uses the files on disk)"; systemctl reboot; }
fi
exit 1
}
+11 -3
View File
@@ -354,10 +354,18 @@ STUB
a_is "stage2: exit 1" "$rc" 1; a_is "stage2: status" "$(st_word)" rolled-back
[ ! -e "$sb/netplan/50-van-wan.yaml" ] && [ -e "$sb/netplan/10-dhcp-all-interfaces.yaml" ] && ok "apply helper stage2: restored" || bad "apply helper stage2: not restored"
rm -rf "$sb"
# (6) no connectivity even after rollback: last-resort reboot
# (6) clean rollback but no connectivity (uplink unplugged): must NOT reboot
an_run STUB_ROUTE=none
a_is "no connectivity: status" "$(st_word)" rollback-failed
grep -q '^systemctl reboot' "$sb/calls" && ok "apply helper: reboots when connectivity is not back after rollback" || bad "apply helper: no reboot"
a_is "no connectivity after clean rollback: exit" "$rc" 1
a_is "no connectivity after clean rollback: status" "$(cat "$sb/status" 2>/dev/null | cut -d' ' -f1,3)" "rolled-back restored-no-connectivity"
grep -q 'restored, but no connectivity' "$sb/log" && ok "apply helper: no-connectivity log" || bad "apply helper: no-connectivity log"
grep -q '^systemctl reboot' "$sb/calls" && bad "apply helper: must not reboot after a clean rollback" || ok "apply helper: no reboot after a clean rollback"
[ -e "$sb/netplan/10-dhcp-all-interfaces.yaml" ] && [ ! -e "$sb/netplan/50-van-wan.yaml" ] && ok "apply helper: clean rollback restored files" || bad "apply helper: clean rollback files"
rm -rf "$sb"
# (7) rollback cp fails AND no connectivity: last-resort reboot
AN_NOBAK=1 an_run STUB_ROUTE=none
a_is "failed rollback, no connectivity: status" "$(st_word)" rollback-failed
grep -q '^systemctl reboot' "$sb/calls" && ok "apply helper: reboots when the rollback failed and connectivity is absent" || bad "apply helper: no reboot after failed rollback"
rm -rf "$sb"
rm -rf "$stubs"
fi