bitsy-ai / printnanny-os

Image repository, change logs, and issue tracking for PrintNanny OS
GNU Affero General Public License v3.0
23 stars 2 forks source link

.swu patch files should be downloaded to /data and rotated #186

Closed leigh-johnson closed 1 year ago

leigh-johnson commented 1 year ago

Describe the bug

Right now, .swu files are downloaded to /run which is a volatile memory tmpfs. If the Pi is under even a moderate amount of memory pressure, the 700mb+ .swu file will fail to download. We should download this file to a persistent path under /data and rotate old images.

leigh-johnson commented 1 year ago

Digging into this one today! I just realized that swu patching should be zero-copy, indicated by the installed-directly = true; setting in the root filesystem description. So the fact that updates are being saved to a file and then applied is a bug, or the installed-directly setting isn't being applied.

https://github.com/bitsy-ai/meta-bitsy/blob/main/meta-printnanny/recipes-core/images/files/raspberrypi4-64/sw-description#L13

From swupdate docs:

* reads through the cpio archive one file at a time and either:
    ** execute handlers for each file marked as "installed-directly". checksum is checked while the data is streamed to handler, and copy will be marked as having failed if checksum was not correct failing the rest of the install.
    ** copy other files to a temporary location while checking checksums, stopping if there was a mismatch.

https://github.com/sbabic/swupdate/blob/master/doc/source/swupdate.rst#running-swupdate

leigh-johnson commented 1 year ago

Looks like nginx is responsible for buffering the file to /var/run/nginx instead of streaming the bytes over to the mongoose server. 👀

Jan 05 09:28:21 pn-v0-5 nginx[688]: 2023/01/05 09:28:21 [warn] 688#688: *4 a client request body is buffered to a temporary file /run/nginx/client_body_temp/0000000001, >
leigh-johnson commented 1 year ago

:tada: WOO, swupdate patching is now zero-copy.

To recap how this works:

  1. PrintNanny OS image contains four disk partitions: boot, rootfs1, rootfs2, data
  2. One rootfs partition is active, one is inactive
  3. When you apply a .swu patch, the patch is streamed directly to the inactive partition.
  4. After applying a patch, swupdate will flip the active partition bit.
  5. If the boot fails, swupdate will reset the active partition bt.
  6. If the boot succeeds, the "new" partition remains active and the "old" partition is now inactive and will be used for the NEXT streaming update.

[extract_files] : Installing STREAM printnanny-release-image-raspberrypi4-64.ext4.gz, 756257029 bytes

Screenshot from 2023-01-05 10-10-51