Improve firmware failure error recovery (#683)

This commit is contained in:
Tim Wilkinson 2023-01-29 19:21:03 -08:00 committed by GitHub
parent f733592438
commit fdb9270617
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 27 deletions

View File

@ -39,23 +39,36 @@ LICENSE
# #
SERVICES="dnsmasq:dnsmasq dropbear:dropbear urngd:urngd rpcd:rpcd telnet:telnetd manager:manager.lua log:logd" SERVICES="dnsmasq:dnsmasq dropbear:dropbear urngd:urngd rpcd:rpcd telnet:telnetd manager:manager.lua log:logd"
# if [ "$1" = "restore" ]; then
# We unceremoniously kill services, and then stop them to prevent #
# procd restarting them again # Restart everything
# #
for S in ${SERVICES} for S in ${SERVICES}
do do
srv=$(echo ${S} | cut -d: -f1) srv=$(echo ${S} | cut -d: -f1)
daemon=$(echo ${S} | cut -d: -f2 -s) if [ -x /etc/init.d/${srv} ]; then
if [ "${daemon}" != "" ]; then /etc/init.d/${srv} start
killall -KILL ${daemon} fi
fi done
if [ -x /etc/init.d/${srv} ]; then else
/etc/init.d/${srv} stop #
fi # We unceremoniously kill services, and then stop them to prevent
done # procd restarting them again
#
for S in ${SERVICES}
do
srv=$(echo ${S} | cut -d: -f1)
daemon=$(echo ${S} | cut -d: -f2 -s)
if [ "${daemon}" != "" ]; then
killall -KILL ${daemon}
fi
if [ -x /etc/init.d/${srv} ]; then
/etc/init.d/${srv} stop
fi
done
# #
# Drop page cache to take pressure of tmps # Drop page cache to take pressure of tmps
# #
echo 3 > /proc/sys/vm/drop_caches echo 3 > /proc/sys/vm/drop_caches
fi

View File

@ -35,19 +35,19 @@ remove_opkg_lists() {
return_to_operating_mode() { return_to_operating_mode() {
# If anything goes wrong after this point return the error code to the calling process
# as we could be in an unstable state.
set -e
# Start up the services we stopped # Start up the services we stopped
err=0
for name in $serviceslist for name in $serviceslist
do do
"/etc/init.d/${name}" start "/etc/init.d/${name}" start
if [ "$?" != "0" ]; then
err=-1
fi
done done
rm -f /tmp/.upgrade_mode rm -f /tmp/.upgrade_mode
exit $err
} }

View File

@ -188,7 +188,7 @@ if os.getenv("REQUEST_METHOD") == "POST" then
firmfile = meta.file firmfile = meta.file
if firmfile:match("sysupgrade%.bin$") then if firmfile:match("sysupgrade%.bin$") then
-- Uploading a system upgrade - clear out memory early -- Uploading a system upgrade - clear out memory early
os.execute("/usr/local/bin/upgrade_prepare.sh > /dev/null 2>&1") os.execute("/usr/local/bin/upgrade_prepare.sh stop > /dev/null 2>&1")
end end
end end
nixio.fs.mkdir("/tmp/web/upload") nixio.fs.mkdir("/tmp/web/upload")
@ -398,7 +398,7 @@ if parms.button_apply_fw and nixio.fs.stat("/tmp/web/local_firmware.bin") then
os.execute("mv -f /tmp/web/local_firmware.bin /tmp/web/upload/file") os.execute("mv -f /tmp/web/local_firmware.bin /tmp/web/upload/file")
firmfile = "arednmesh-sideload-sysupgrade.bin" firmfile = "arednmesh-sideload-sysupgrade.bin"
parms.button_ul_fw = "Upload" parms.button_ul_fw = "Upload"
os.execute("/usr/local/bin/upgrade_prepare.sh > /dev/null 2>&1") os.execute("/usr/local/bin/upgrade_prepare.sh stop > /dev/null 2>&1")
end end
-- upload fw -- upload fw
@ -423,6 +423,7 @@ if parms.button_ul_fw and nixio.fs.stat("/tmp/web/upload/file") then
fwout("Firmware CANNOT be updated") fwout("Firmware CANNOT be updated")
fwout("the uploaded file is not recognized") fwout("the uploaded file is not recognized")
nixio.fs.remove(tmpdir .. "/firmware") nixio.fs.remove(tmpdir .. "/firmware")
os.execute("/usr/local/bin/upgrade_prepare.sh restore > /dev/null 2>&1")
if os.execute("/usr/local/bin/uploadctlservices restore > /dev/null 2>&1") ~= 0 then if os.execute("/usr/local/bin/uploadctlservices restore > /dev/null 2>&1") ~= 0 then
fwout("Failed to restart all services, please reboot this node.") fwout("Failed to restart all services, please reboot this node.")
end end
@ -434,7 +435,7 @@ if parms.button_dl_fw and parms.dl_fw ~= "default" then
if get_default_gw() ~= "none" or uciserverpath:match("%.local%.mesh") then if get_default_gw() ~= "none" or uciserverpath:match("%.local%.mesh") then
nixio.fs.remove(tmpdir .. "/firmware") nixio.fs.remove(tmpdir .. "/firmware")
os.execute("/usr/local/bin/uploadctlservices update > /dev/null 2>&1") os.execute("/usr/local/bin/uploadctlservices update > /dev/null 2>&1")
os.execute("/usr/local/bin/upgrade_prepare.sh > /dev/null 2>&1") os.execute("/usr/local/bin/upgrade_prepare.sh stop > /dev/null 2>&1")
fw_install = false fw_install = false
local err local err
@ -478,6 +479,7 @@ if parms.button_dl_fw and parms.dl_fw ~= "default" then
if err then if err then
fwout("Firmware CANNOT be updated") fwout("Firmware CANNOT be updated")
fwout(err) fwout(err)
os.execute("/usr/local/bin/upgrade_prepare.sh restore > /dev/null 2>&1")
if os.execute("/usr/local/bin/uploadctlservices restore > /dev/null 2>&1") ~= 0 then if os.execute("/usr/local/bin/uploadctlservices restore > /dev/null 2>&1") ~= 0 then
fwout("Failed to restart all services, please reboot this node.") fwout("Failed to restart all services, please reboot this node.")
end end