Skip to content

Commit 4b95de9

Browse files
committed
fixup! feat: Boot count with fallback to old system [WIP]
1 parent dcb7216 commit 4b95de9

File tree

9 files changed

+64
-14
lines changed

9 files changed

+64
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
#!/bin/sh
22

3+
systemctl is-active --quiet app || {
4+
echo "Remote app not running!"
5+
exit 1
6+
}
7+
38
ISUPGRADING=$(fw_printenv upgrade_available | awk -F'=' '{print $2}')
49
echo "upgrade_available=$ISUPGRADING"
510
if [ -z "$ISUPGRADING" ]
611
then
7-
echo "No RootFs update pending"
12+
echo "No system update pending"
813
else
9-
echo "RootFs update pending, verifying system"
14+
echo "System update pending, verifying system..."
15+
# TODO refactor once there are any common system checks:
16+
# - call script from systemd right after app start (instead of delayed timer)
17+
# - get pid of app
18+
# - perform system checks
19+
# - wait ~ 3 min
20+
# - check if app is still running and has same pid (i.e. didn't get auto-restarted)
21+
1022
# Perform extra checks here.
1123
# If anything went wrong, reboot again until the bootlimit is reached
1224
# which triggers a rollback of the RootFs
25+
26+
# It's all good! Clear upgrade status and mark partition ok.
1327
fw_setenv upgrade_available
1428
fw_setenv bootcount 0
29+
echo "System update successful. Marked current partition OK."
1530
fi
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
#!/bin/sh
22

3+
systemctl is-active --quiet app || {
4+
echo "Remote app not running!"
5+
exit 1
6+
}
7+
38
ISUPGRADING=$(fw_printenv upgrade_available | awk -F'=' '{print $2}')
49
echo "upgrade_available=$ISUPGRADING"
510
if [ -z "$ISUPGRADING" ]
611
then
7-
echo "No RootFs update pending"
12+
echo "No system update pending"
813
else
9-
echo "RootFs update pending, verifying system"
14+
echo "System update pending, verifying system..."
15+
# TODO refactor once there are any common system checks:
16+
# - call script from systemd right after app start (instead of delayed timer)
17+
# - get pid of app
18+
# - perform system checks
19+
# - wait ~ 3 min
20+
# - check if app is still running and has same pid (i.e. didn't get auto-restarted)
21+
1022
# Perform extra checks here.
1123
# If anything went wrong, reboot again until the bootlimit is reached
1224
# which triggers a rollback of the RootFs
25+
26+
# It's all good! Clear upgrade status and mark partition ok.
1327
fw_setenv upgrade_available
1428
fw_setenv bootcount 0
29+
echo "System update successful. Marked current partition OK."
1530
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[Unit]
2+
Description=Run bootcount reset check after app update script
3+
RefuseManualStart=no
4+
RefuseManualStop=no
5+
6+
[Service]
7+
Type=oneshot
8+
ExecStart=/etc/swupdate/reset-bootcount.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[Unit]
2+
Description=Bootcount reset check after app update timer
3+
4+
[Timer]
5+
OnBootSec=180
6+
7+
[Install]
8+
WantedBy=multi-user.target

buildroot-external/rootfs-overlay/etc/systemd/system/app.service

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ Description=YIO remote app
33
After=display-init.service
44

55
[Service]
6-
Type=simple
6+
Type=exec
77
ExecStart=/opt/yio/app-launch.sh
8-
RemainAfterExit=yes
8+
# Force reboot if app failed to startup 2 times within 60 seconds
9+
StartLimitIntervalSec=60
10+
StartLimitBurst=2
11+
Restart=always
12+
RestartSec=1
13+
StartLimitAction=reboot-force
914

1015
[Install]
1116
WantedBy=multi-user.target
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../app-update-bootcount.timer

buildroot-external/rootfs-overlay/opt/yio/app-launch.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ if [[ ! -d $YIO_APP_DIR ]] && [[ -d ${YIO_HOME}/app-previous ]]; then
1414
mv ${YIO_HOME}/app-previous $YIO_APP_DIR
1515
fi
1616

17-
${YIO_APP_DIR}/remote &
17+
# Do not fork! Otherwise systemd unit service doesn't work anymore
18+
${YIO_APP_DIR}/remote

buildroot-external/rootfs-overlay/opt/yio/scripts/app-plugin-update.sh

+2-5
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ fi
151151
# Replace old backup with the current app version
152152
#------------------------------------------------------------------------------
153153
log "Stopping remote app..."
154-
killall -9 remote >> $LOGFILE 2>&1 && sleep 2 || true
155-
#stopService app >> $LOGFILE 2>&1#
154+
stopService app >> $LOGFILE 2>&1
156155

157156
#fbv -d 1 "${YIO_SPLASH_DIR}/update.png"
158157

@@ -195,6 +194,4 @@ fbv -d 1 "${YIO_SPLASH_DIR}/splash.png"
195194
#TODO rather reboot? If yes: it would be a good time to check & repair file systems
196195
log "Update finished! Launching app..."
197196

198-
# 'systemctl start app' doesn't work reliably!?
199-
# startService app
200-
$YIO_HOME/app-launch.sh >> /dev/null 2>&1
197+
startService app

buildroot-external/rootfs-overlay/opt/yio/scripts/app-update.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ fi
148148
#------------------------------------------------------------------------------
149149
# Replace old backup with the current app version
150150
#------------------------------------------------------------------------------
151-
killall -9 remote >> $LOGFILE 2>&1 && sleep 2 || true
151+
stopService app >> $LOGFILE 2>&1
152152

153153
if [[ -d $YIO_APP_DIR ]]; then
154154
YIO_BACKUP=${YIO_HOME}/app-previous
@@ -189,4 +189,4 @@ log "Update finished! Launching app..."
189189

190190
fbv -d 1 "${YIO_SPLASH_DIR}/splash.png"
191191

192-
$YIO_HOME/app-launch.sh >> /dev/null 2>&1
192+
startService app

0 commit comments

Comments
 (0)