fix(deploy): no dangling symlink on first-deploy failure, deadline-capped health poll, release pruning, honest commit rc

This commit is contained in:
2026-08-22 19:18:42 -06:00
parent 92a2a6d8ee
commit 6b84665347
3 changed files with 23 additions and 9 deletions
@@ -79,7 +79,10 @@ def restore(name):
if rc != 0:
return {'ok': False, 'restored': restored,
'error': 'import failed'}
run_cmd(['uci', 'commit', cfg])
crc, _, cerr = run_cmd(['uci', 'commit', cfg])
if crc != 0:
return {'ok': False, 'restored': restored,
'error': 'commit failed: %s' % (cerr or cfg)}
restored.append(cfg)
return {'ok': True, 'restored': restored}
+19 -5
View File
@@ -228,7 +228,11 @@ ln -sfn \"\$RELDIR\" \"\$CURRENT\"
rollback_install() {
rm -rf \"\$LIVE\"
[ ! -d \"\$BACKUP\" ] || mv \"\$BACKUP\" \"\$LIVE\"
[ -z \"\$PREV\" ] || ln -sfn \"\$PREV\" \"\$CURRENT\"
if [ -n \"\$PREV\" ]; then
ln -sfn \"\$PREV\" \"\$CURRENT\"
else
rm -f \"\$CURRENT\"
fi
}
if [ -d \"\$LIVE\" ]; then mv \"\$LIVE\" \"\$BACKUP\"; fi
if ! mkdir -p \"\$LIVE\" || ! cp -a \"\$NEW/.\" \"\$LIVE/\"; then
@@ -243,16 +247,16 @@ chmod 755 /etc/init.d/mk8-guard
/etc/init.d/mk8-guard enable
/etc/init.d/pagerwebui start
# Post-deploy verification: API must answer within 60s or we roll back.
i=0
# Post-deploy verification: API must answer within ~60s (deadline-capped so
# hung connections cannot stretch the window) or we roll back.
DEADLINE=\$((SECONDS + 60))
HEALTH_OK=''
while [ \$i -lt 60 ]; do
while [ \$SECONDS -lt \$DEADLINE ]; do
if curl -fsS -m 3 http://127.0.0.1:8080/ >/dev/null 2>&1; then
HEALTH_OK=1
break
fi
sleep 1
i=\$((i+1))
done
if [ -z \"\$HEALTH_OK\" ]; then
echo 'post-deploy health check failed; rolling back' >&2
@@ -263,6 +267,16 @@ if [ -z \"\$HEALTH_OK\" ]; then
exit 1
fi
rm -rf \"\$BACKUP\"
# Prune old releases; keep the newest 3 including current.
ALL=\$(ls -1d /mmc/mk8/releases/2* 2>/dev/null | sort)
TOTAL=\$(printf '%s\\n' \"\$ALL\" | grep -c .)
KEEP_FROM=\$((TOTAL - 2))
if [ \"\$KEEP_FROM\" -gt 1 ]; then
printf '%s\\n' \"\$ALL\" | awk -v kf=\"\$KEEP_FROM\" 'NR < kf' | while read r; do
CUR=\$(readlink \$CURRENT 2>/dev/null || true)
[ \"\$r\" = \"\$CUR\" ] || rm -rf \"\$r\"
done
fi
echo RELEASE_OK@\"\$RELDIR\""
if run_ssh "$TARGET" "$REMOTE_COMMAND"; then
printf 'Release active: /mmc/mk8/releases/%s\n' "$RELEASE_TS"
-3
View File
@@ -221,9 +221,6 @@ class ReliabilityApiTest(unittest.TestCase):
self.assertTrue(raises)
self.assertEqual(calls['events'][-1][0], 'profile_restore')
status, result = server.h_profile_restore(
_Ctx({'name': 'missing'}))
def missing_restore(name):
calls['restored'] = name
return {'ok': False, 'restored': [], 'error': 'not found'}