Skip to content

A rootless Android app that boots Alpine Linux: run containers (Podman/Docker/LXC) and GUI desktop apps.

fix(guest): stop migrations at the first failure

ExTvfe2778af9948
diff --git a/build-rootfs/build-rootfs.sh b/build-rootfs/build-rootfs.sh
index 424ba39..9c03913 100755
--- a/build-rootfs/build-rootfs.sh
+++ b/build-rootfs/build-rootfs.sh
@@ -141,6 +141,12 @@ chmod 0644 "$ROOTFS/etc/podroid/forwards.conf"
# Migration scripts dir (seeded with its README; per-version <v>.sh added over time).
mkdir -p "$ROOTFS/etc/podroid/migrations"
cp /work/files/etc/podroid/migrations/README "$ROOTFS/etc/podroid/migrations/README"
+# Install every migration script so a new one needs no build-script edit.
+for f in /work/files/etc/podroid/migrations/*.sh; do
+ [ -f "$f" ] || continue
+ cp "$f" "$ROOTFS/etc/podroid/migrations/"
+ chmod 0755 "$ROOTFS/etc/podroid/migrations/$(basename "$f")"
+done
# System-version stamp: the migration anchor. Baked from the app versionCode at
# build time; compared against /mnt/persist/.podroid/applied-version at boot.
printf '%s\n' "${SYSTEM_VERSION:-0}" > "$ROOTFS/etc/podroid/system-version"
diff --git a/build-rootfs/files/etc/init.d/podroid-migrate b/build-rootfs/files/etc/init.d/podroid-migrate
index 58566d3..daf477d 100644
--- a/build-rootfs/files/etc/init.d/podroid-migrate
+++ b/build-rootfs/files/etc/init.d/podroid-migrate
@@ -36,17 +36,33 @@ start() {
# Run each migrations/<v>.sh with applied < v <= current, in ascending
# numeric order (sort the basenames, not full paths). Scripts MUST be
- # idempotent (a crash mid-run re-runs them next boot).
+ # idempotent (a crash mid-run re-runs them next boot). Stop at the first
+ # failure so the failed script and any after it re-run next boot instead
+ # of being marked applied.
+ last_ok="$applied"
+ failed=0
for base in $(ls "$MIGRATIONS_DIR" 2>/dev/null | sed -n 's/\.sh$//p' | sort -n); do
case "$base" in *[!0-9]*) continue ;; esac # digits only
if [ "$base" -gt "$applied" ] 2>/dev/null && [ "$base" -le "$current" ] 2>/dev/null; then
echo "podroid-migrate: applying $base" > /dev/console
- sh "$MIGRATIONS_DIR/$base.sh" > /dev/console 2>&1 \
- || echo "podroid-migrate: $base failed (continuing)" > /dev/console
+ if sh "$MIGRATIONS_DIR/$base.sh" > /dev/console 2>&1; then
+ last_ok="$base"
+ else
+ echo "podroid-migrate: $base failed, stopping (will retry next boot)" > /dev/console
+ failed=1
+ break
+ fi
fi
done
- # Advance the marker atomically only after the loop completes.
- printf '%s\n' "$current" > "$APPLIED_FILE.tmp" && mv "$APPLIED_FILE.tmp" "$APPLIED_FILE"
+ # Advance the marker atomically: to current if the loop completed with no
+ # failure, otherwise to the last successfully applied version (unchanged
+ # if none succeeded), never past a failure.
+ if [ "$failed" -eq 0 ]; then
+ marker="$current"
+ else
+ marker="$last_ok"
+ fi
+ printf '%s\n' "$marker" > "$APPLIED_FILE.tmp" && mv "$APPLIED_FILE.tmp" "$APPLIED_FILE"
eend 0
}