Skip to content

Commit

Permalink
Merge pull request #25 from thin-edge/feat-auto-rollback
Browse files Browse the repository at this point in the history
feat: add auto rollback service in case new image does not have a functioning agent
  • Loading branch information
reubenmiller authored Dec 5, 2023
2 parents 3601227 + 7d99081 commit 0958fca
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 20 deletions.
File renamed without changes.
2 changes: 2 additions & 0 deletions recipes/health-check/recipe.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
description = "Health check runner"
priority = 80_000
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,3 @@ chmod 755 /etc/health.d

install -D -m 755 "${RECIPE_DIR}/files/health.d/"* -t /etc/health.d/
install -D -m 755 "${RECIPE_DIR}/files/healthcheck.sh" -t /usr/bin/
install -D -m 644 "${RECIPE_DIR}/files/rugpi-auto-rollback.service" -t /usr/lib/systemd/system/

if [ "${RECIPE_PARAM_ENABLED}" = "true" ]; then
systemctl enable rugpi-auto-rollback
fi
9 changes: 0 additions & 9 deletions recipes/rugpi-auto-rollback/files/rugpi-auto-rollback.service

This file was deleted.

5 changes: 0 additions & 5 deletions recipes/rugpi-auto-rollback/recipe.toml

This file was deleted.

15 changes: 15 additions & 0 deletions recipes/tedge-firmware-update/files/firmware-auto-rollback
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
set -e

RUGPI_INFO=$(rugpi-ctrl system info ||:)
HOT=$(echo "$RUGPI_INFO" | grep Hot | cut -d: -f2 | xargs)
DEFAULT=$(echo "$RUGPI_INFO" | grep Default | cut -d: -f2 | xargs)

if [ "$HOT" = "$DEFAULT" ]; then
echo "Already on default partition. Nothing to rollback to. hot=$HOT, default=$DEFAULT" >&2
exit 0
fi

echo "Rebooting into default partition. hot=$HOT, default=$DEFAULT"
reboot
exit 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Rollback to default partition if this service has not been disabled yet

[Service]
Type=oneshot
ExecStart=/usr/bin/firmware-auto-rollback

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
Description=rugpi auto rollback

[Timer]
OnBootSec=1800s

[Install]
WantedBy=timers.target
5 changes: 4 additions & 1 deletion recipes/tedge-firmware-update/recipe.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
description = "Add workflow scripts to support firmware updates"
default = false
priority = 10_000
dependencies = ["thin-edge.io"]
dependencies = ["thin-edge.io", "health-check"]

[parameters]
autorollback = { default = true }
9 changes: 9 additions & 0 deletions recipes/tedge-firmware-update/steps/00-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,14 @@ install -D -m 644 "${RECIPE_DIR}/files/firware_update.rugpi.toml" -t /usr/share/
install -D -m 755 "${RECIPE_DIR}/files/rugpi_workflow.sh" -t /usr/bin/
install -D -m 755 "${RECIPE_DIR}/files/firmware-version" /usr/share/tedge-inventory/scripts.d/80_c8y_Firmware

# auto rollback service incase if new agent is corrupt (only rely on tooling which is definitely there)
install -D -m 755 "${RECIPE_DIR}/files/firmware-auto-rollback" /usr/bin/firmware-auto-rollback
install -D -m 644 "${RECIPE_DIR}/files/firmware-auto-rollback.service" -t /usr/lib/systemd/system/
install -D -m 644 "${RECIPE_DIR}/files/firmware-auto-rollback.timer" -t /usr/lib/systemd/system/

if [ "${RECIPE_PARAM_AUTOROLLBACK}" = "true" ]; then
systemctl enable firmware-auto-rollback.timer
fi

# Use symlink so that the workflow file can be updated within the image
ln -s /usr/share/tedge-workflows/firware_update.rugpi.toml /etc/tedge/operations/firmware_update.toml

0 comments on commit 0958fca

Please sign in to comment.