fix(deploy): no dangling symlink on first-deploy failure, deadline-capped health poll, release pruning, honest commit rc
This commit is contained in:
@@ -79,7 +79,10 @@ def restore(name):
|
|||||||
if rc != 0:
|
if rc != 0:
|
||||||
return {'ok': False, 'restored': restored,
|
return {'ok': False, 'restored': restored,
|
||||||
'error': 'import failed'}
|
'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)
|
restored.append(cfg)
|
||||||
return {'ok': True, 'restored': restored}
|
return {'ok': True, 'restored': restored}
|
||||||
|
|
||||||
|
|||||||
+19
-5
@@ -228,7 +228,11 @@ ln -sfn \"\$RELDIR\" \"\$CURRENT\"
|
|||||||
rollback_install() {
|
rollback_install() {
|
||||||
rm -rf \"\$LIVE\"
|
rm -rf \"\$LIVE\"
|
||||||
[ ! -d \"\$BACKUP\" ] || mv \"\$BACKUP\" \"\$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 [ -d \"\$LIVE\" ]; then mv \"\$LIVE\" \"\$BACKUP\"; fi
|
||||||
if ! mkdir -p \"\$LIVE\" || ! cp -a \"\$NEW/.\" \"\$LIVE/\"; then
|
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/mk8-guard enable
|
||||||
/etc/init.d/pagerwebui start
|
/etc/init.d/pagerwebui start
|
||||||
|
|
||||||
# Post-deploy verification: API must answer within 60s or we roll back.
|
# Post-deploy verification: API must answer within ~60s (deadline-capped so
|
||||||
i=0
|
# hung connections cannot stretch the window) or we roll back.
|
||||||
|
DEADLINE=\$((SECONDS + 60))
|
||||||
HEALTH_OK=''
|
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
|
if curl -fsS -m 3 http://127.0.0.1:8080/ >/dev/null 2>&1; then
|
||||||
HEALTH_OK=1
|
HEALTH_OK=1
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
sleep 1
|
sleep 1
|
||||||
i=\$((i+1))
|
|
||||||
done
|
done
|
||||||
if [ -z \"\$HEALTH_OK\" ]; then
|
if [ -z \"\$HEALTH_OK\" ]; then
|
||||||
echo 'post-deploy health check failed; rolling back' >&2
|
echo 'post-deploy health check failed; rolling back' >&2
|
||||||
@@ -263,6 +267,16 @@ if [ -z \"\$HEALTH_OK\" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
rm -rf \"\$BACKUP\"
|
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\""
|
echo RELEASE_OK@\"\$RELDIR\""
|
||||||
if run_ssh "$TARGET" "$REMOTE_COMMAND"; then
|
if run_ssh "$TARGET" "$REMOTE_COMMAND"; then
|
||||||
printf 'Release active: /mmc/mk8/releases/%s\n' "$RELEASE_TS"
|
printf 'Release active: /mmc/mk8/releases/%s\n' "$RELEASE_TS"
|
||||||
|
|||||||
@@ -221,9 +221,6 @@ class ReliabilityApiTest(unittest.TestCase):
|
|||||||
self.assertTrue(raises)
|
self.assertTrue(raises)
|
||||||
self.assertEqual(calls['events'][-1][0], 'profile_restore')
|
self.assertEqual(calls['events'][-1][0], 'profile_restore')
|
||||||
|
|
||||||
status, result = server.h_profile_restore(
|
|
||||||
_Ctx({'name': 'missing'}))
|
|
||||||
|
|
||||||
def missing_restore(name):
|
def missing_restore(name):
|
||||||
calls['restored'] = name
|
calls['restored'] = name
|
||||||
return {'ok': False, 'restored': [], 'error': 'not found'}
|
return {'ok': False, 'restored': [], 'error': 'not found'}
|
||||||
|
|||||||
Reference in New Issue
Block a user