diff --git a/files/usr/local/bin/upgrade_prepare.sh b/files/usr/local/bin/upgrade_prepare.sh index 7220674f..d6ff0bdb 100755 --- a/files/usr/local/bin/upgrade_prepare.sh +++ b/files/usr/local/bin/upgrade_prepare.sh @@ -39,23 +39,36 @@ LICENSE # SERVICES="dnsmasq:dnsmasq dropbear:dropbear urngd:urngd rpcd:rpcd telnet:telnetd manager:manager.lua log:logd" -# -# We unceremoniously kill services, and then stop them to prevent -# 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 +if [ "$1" = "restore" ]; then + # + # Restart everything + # + for S in ${SERVICES} + do + srv=$(echo ${S} | cut -d: -f1) + if [ -x /etc/init.d/${srv} ]; then + /etc/init.d/${srv} start + fi + done +else + # + # We unceremoniously kill services, and then stop them to prevent + # 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 -# -echo 3 > /proc/sys/vm/drop_caches + # + # Drop page cache to take pressure of tmps + # + echo 3 > /proc/sys/vm/drop_caches +fi diff --git a/files/usr/local/bin/uploadctlservices b/files/usr/local/bin/uploadctlservices index 8508733b..9b135b58 100755 --- a/files/usr/local/bin/uploadctlservices +++ b/files/usr/local/bin/uploadctlservices @@ -35,19 +35,19 @@ remove_opkg_lists() { 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 + err=0 for name in $serviceslist do "/etc/init.d/${name}" start + if [ "$?" != "0" ]; then + err=-1 + fi done rm -f /tmp/.upgrade_mode + exit $err } diff --git a/files/www/cgi-bin/admin b/files/www/cgi-bin/admin index 11fbf63d..f17caadc 100755 --- a/files/www/cgi-bin/admin +++ b/files/www/cgi-bin/admin @@ -188,7 +188,7 @@ if os.getenv("REQUEST_METHOD") == "POST" then firmfile = meta.file if firmfile:match("sysupgrade%.bin$") then -- 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 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") firmfile = "arednmesh-sideload-sysupgrade.bin" 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 -- 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("the uploaded file is not recognized") 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 fwout("Failed to restart all services, please reboot this node.") 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 nixio.fs.remove(tmpdir .. "/firmware") 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 local err @@ -478,6 +479,7 @@ if parms.button_dl_fw and parms.dl_fw ~= "default" then if err then fwout("Firmware CANNOT be updated") 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 fwout("Failed to restart all services, please reboot this node.") end