Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.0.x cherry-picks #1660

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions Documentation/update-modules-v3-file-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,29 @@ to make sure the correct partition has been booted.
#### `ArtifactCommit` state

Executes after `ArtifactVerifyReboot`, if `ArtifactVerifyReboot` runs at all, or
else after `ArtifactInstall`. `ArtifactCommit` should be used to make the update
permanent, in cases where it's still possible to roll back.
else after `ArtifactInstall`. `ArtifactCommit` must be used to remove/disable
automatic rollback mechanisms, such as for example the automatic rollback that a
bootloader might do. This essentially makes the update permanent, but it is
important to retain enough data so that an explicit `ArtifactRollback` can still
roll back the update. If additional steps are required to clean up the rollback
data, this should be done in the `Cleanup` state instead.

#### `Cleanup` state

`Cleanup` executes unconditionally at the end of all the other states,
regardless of all outcomes. `Cleanup` can be used to cleanup various temporary
regardless of all outcomes. `Cleanup` can be used to clean up various temporary
files that might have been used during an update, but should not be used to make
any system changes. For example, cleaning up an update that has failed,
returning it to the previous state, should rather be done in the
`ArtifactRollback` state. `Cleanup` is the only additional state that executes
if `Download` fails.
`ArtifactRollback` state. However, rollback data that has been kept around in
order to facilite a rollback (which never happened), should be cleaned up in
`Cleanup`.

It is not necessary to clean up files inside the official update module file
tree, since these will be cleaned up automatically, including any temporary
files.

`Cleanup` is the only additional state that executes if `Download` fails.

### Error states

Expand Down
17 changes: 17 additions & 0 deletions support/modules/rootfs-image
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ set_upgrade_vars() {
passive=$MENDER_ROOTFS_PART_A
passive_num=$MENDER_ROOTFS_PART_A_NUMBER
fi
active_num_hex=$(printf '%x' $active_num)
passive_num_hex=$(printf '%x' $passive_num)
upgrade_available="$(${PRINTENV} upgrade_available)"
upgrade_available="${upgrade_available#upgrade_available=}"
Expand Down Expand Up @@ -195,6 +196,7 @@ case "$STATE" in
ubiupdatevol $passive --size=$size $file
else
cat "$file" > $passive
sync
fi
if [ "$(cat stream-next)" != "" ]; then
echo "More than one file in payload" 1>&2
Expand All @@ -205,6 +207,14 @@ case "$STATE" in
ArtifactInstall)
check_requirements

cat > "$FILES/tmp/orig-part.tmp" <<EOF
orig_part_num=$active_num
orig_part_num_hex=$active_num_hex
EOF
sync "$FILES/tmp/orig-part.tmp"
mv "$FILES/tmp/orig-part.tmp" "$FILES/tmp/orig-part"
sync "$FILES/tmp"

if [ "$upgrade_available" != 0 ]; then
echo "Unexpected \`upgrade_available=$upgrade_available\` in $STATE." 1>&2
exit 1
Expand Down Expand Up @@ -272,6 +282,13 @@ EOF
mender_boot_part=$passive_num
mender_boot_part_hex=$passive_num_hex
upgrade_available=0
EOF
elif [ -f "$FILES/tmp/orig-part" ]; then
. "$FILES/tmp/orig-part"
${SETENV} -s - <<EOF
mender_boot_part=$orig_part_num
mender_boot_part_hex=$orig_part_num_hex
upgrade_available=0
EOF
fi
;;
Expand Down